Skip to content

Commit c07f67a

Browse files
committed
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Problem: Double free when garbage_collect() is used in autocommand. Solution: Have garbage collection also set the copyID in funccal_stack.
1 parent 75ee544 commit c07f67a

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/eval.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,11 @@ eval_clear(void)
430430
vim_free(SCRIPT_SV(i));
431431
ga_clear(&ga_scripts);
432432

433-
// functions need to be freed before gargabe collecting, otherwise local
434-
// variables might be freed twice.
435-
free_all_functions();
436-
437433
// unreferenced lists and dicts
438434
(void)garbage_collect(FALSE);
435+
436+
// functions not garbage collected
437+
free_all_functions();
439438
}
440439
#endif
441440

src/userfunc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4030,11 +4030,18 @@ set_ref_in_funccal(funccall_T *fc, int copyID)
40304030
int
40314031
set_ref_in_call_stack(int copyID)
40324032
{
4033-
int abort = FALSE;
4034-
funccall_T *fc;
4033+
int abort = FALSE;
4034+
funccall_T *fc;
4035+
funccal_entry_T *entry;
40354036

40364037
for (fc = current_funccal; fc != NULL; fc = fc->caller)
40374038
abort = abort || set_ref_in_funccal(fc, copyID);
4039+
4040+
// Also go through the funccal_stack.
4041+
for (entry = funccal_stack; entry != NULL; entry = entry->next)
4042+
for (fc = entry->top_funccal; fc != NULL; fc = fc->caller)
4043+
abort = abort || set_ref_in_funccal(fc, copyID);
4044+
40384045
return abort;
40394046
}
40404047

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ static char *(features[]) =
767767

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1485,
770772
/**/
771773
1484,
772774
/**/

0 commit comments

Comments
 (0)