]> granicus.if.org Git - vim/commitdiff
patch 8.1.1485: double free when garbage_collect() is used in autocommand v8.1.1485
authorBram Moolenaar <Bram@vim.org>
Thu, 6 Jun 2019 17:03:17 +0000 (19:03 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 6 Jun 2019 17:03:17 +0000 (19:03 +0200)
Problem:    Double free when garbage_collect() is used in autocommand.
Solution:   Have garbage collection also set the copyID in funccal_stack.

src/eval.c
src/userfunc.c
src/version.c

index 5452f45437d7ace82641ce6eaea0e88e1b76974b..abb3b40692358459c17b6c8e4c48e08bb9c87e88 100644 (file)
@@ -430,12 +430,11 @@ eval_clear(void)
        vim_free(SCRIPT_SV(i));
     ga_clear(&ga_scripts);
 
-    // functions need to be freed before gargabe collecting, otherwise local
-    // variables might be freed twice.
-    free_all_functions();
-
     // unreferenced lists and dicts
     (void)garbage_collect(FALSE);
+
+    // functions not garbage collected
+    free_all_functions();
 }
 #endif
 
index 7abde07e354c9f1a1f739811dd6da55de015177b..3a0219af46a0538ab4be7536a4d1d1b0cfcce3f3 100644 (file)
@@ -4030,11 +4030,18 @@ set_ref_in_funccal(funccall_T *fc, int copyID)
     int
 set_ref_in_call_stack(int copyID)
 {
-    int                abort = FALSE;
-    funccall_T *fc;
+    int                        abort = FALSE;
+    funccall_T         *fc;
+    funccal_entry_T    *entry;
 
     for (fc = current_funccal; fc != NULL; fc = fc->caller)
        abort = abort || set_ref_in_funccal(fc, copyID);
+
+    // Also go through the funccal_stack.
+    for (entry = funccal_stack; entry != NULL; entry = entry->next)
+       for (fc = entry->top_funccal; fc != NULL; fc = fc->caller)
+           abort = abort || set_ref_in_funccal(fc, copyID);
+
     return abort;
 }
 
index bbfbfe17d7f4e0dd3b6315685aa9206c0a3c59ca..4c44f2e3cb80db86759e88001ea560c093301939 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1485,
 /**/
     1484,
 /**/