mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1865: Vim9: garbage collection may cause crash
Problem: Vim9: garbage collection may cause crash Solution: validate that class members typeval is not null closes: #13028 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
623ba31821
commit
544be0d893
13
src/eval.c
13
src/eval.c
@ -5725,10 +5725,15 @@ set_ref_in_item_class(
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
cl->class_copyID = copyID;
|
cl->class_copyID = copyID;
|
||||||
for (int i = 0; !abort && i < cl->class_class_member_count; ++i)
|
if (cl->class_members_tv != NULL)
|
||||||
abort = abort || set_ref_in_item(
|
{
|
||||||
&cl->class_members_tv[i],
|
// The "class_members_tv" table is allocated only for regular classes
|
||||||
copyID, ht_stack, list_stack);
|
// and not for interfaces.
|
||||||
|
for (int i = 0; !abort && i < cl->class_class_member_count; ++i)
|
||||||
|
abort = abort || set_ref_in_item(
|
||||||
|
&cl->class_members_tv[i],
|
||||||
|
copyID, ht_stack, list_stack);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; !abort && i < cl->class_class_function_count; ++i)
|
for (int i = 0; !abort && i < cl->class_class_function_count; ++i)
|
||||||
abort = abort || set_ref_in_func(NULL,
|
abort = abort || set_ref_in_func(NULL,
|
||||||
|
@ -1307,6 +1307,60 @@ func Test_class_garbagecollect()
|
|||||||
call v9.CheckScriptSuccess(lines)
|
call v9.CheckScriptSuccess(lines)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test interface garbage collection
|
||||||
|
func Test_interface_garbagecollect()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
interface I
|
||||||
|
static ro_class_var: number
|
||||||
|
public static rw_class_var: number
|
||||||
|
static _priv_class_var: number
|
||||||
|
this.ro_obj_var: number
|
||||||
|
public this.rw_obj_var: number
|
||||||
|
this._priv_obj_var: number
|
||||||
|
|
||||||
|
static def ClassFoo(): number
|
||||||
|
static def _ClassBar(): number
|
||||||
|
def ObjFoo(): number
|
||||||
|
def _ObjBar(): number
|
||||||
|
endinterface
|
||||||
|
|
||||||
|
class A implements I
|
||||||
|
static ro_class_var: number = 10
|
||||||
|
public static rw_class_var: number = 20
|
||||||
|
static _priv_class_var: number = 30
|
||||||
|
this.ro_obj_var: number = 40
|
||||||
|
public this.rw_obj_var: number = 50
|
||||||
|
this._priv_obj_var: number = 60
|
||||||
|
|
||||||
|
static def _ClassBar(): number
|
||||||
|
return _priv_class_var
|
||||||
|
enddef
|
||||||
|
|
||||||
|
static def ClassFoo(): number
|
||||||
|
return ro_class_var + rw_class_var + A._ClassBar()
|
||||||
|
enddef
|
||||||
|
|
||||||
|
def _ObjBar(): number
|
||||||
|
return this._priv_obj_var
|
||||||
|
enddef
|
||||||
|
|
||||||
|
def ObjFoo(): number
|
||||||
|
return this.ro_obj_var + this.rw_obj_var + this._ObjBar()
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
|
||||||
|
assert_equal(60, A.ClassFoo())
|
||||||
|
var o = A.new()
|
||||||
|
assert_equal(150, o.ObjFoo())
|
||||||
|
test_garbagecollect_now()
|
||||||
|
assert_equal(60, A.ClassFoo())
|
||||||
|
assert_equal(150, o.ObjFoo())
|
||||||
|
END
|
||||||
|
call v9.CheckScriptSuccess(lines)
|
||||||
|
endfunc
|
||||||
|
|
||||||
def Test_class_function()
|
def Test_class_function()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@ -699,6 +699,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1865,
|
||||||
/**/
|
/**/
|
||||||
1864,
|
1864,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user