patch 9.0.1865: Vim9: garbage collection may cause crash

Commit: 
https://github.com/vim/vim/commit/544be0d893e68c494aed09232d5bee4ca8b74619
Author: Yegappan Lakshmanan <[email protected]>
Date:   Mon Sep 4 22:14:28 2023 +0200

    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 <[email protected]>
    Co-authored-by: Yegappan Lakshmanan <[email protected]>

diff --git a/src/eval.c b/src/eval.c
index 4143dd2ac..7cfe68cc6 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -5725,10 +5725,15 @@ set_ref_in_item_class(
        return FALSE;
 
     cl->class_copyID = copyID;
-    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);
+    if (cl->class_members_tv != NULL)
+    {
+       // The "class_members_tv" table is allocated only for regular classes
+       // 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)
        abort = abort || set_ref_in_func(NULL,
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 72cdaf086..8ae136f28 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -1307,6 +1307,60 @@ func Test_class_garbagecollect()
   call v9.CheckScriptSuccess(lines)
 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()
   var lines =<< trim END
       vim9script
diff --git a/src/version.c b/src/version.c
index c2faee46c..c4b793f50 100644
--- a/src/version.c
+++ b/src/version.c
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1865,
 /**/
     1864,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qdGCx-00FSKn-9x%40256bit.org.

Raspunde prin e-mail lui