mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 8.1.0800: may use a lot of memory when a function refers itself
Problem: May use a lot of memory when a function creates a cyclic reference. Solution: After saving a funccal many times, invoke the garbage collector. (closes #3835)
This commit is contained in:
@@ -651,6 +651,7 @@ cleanup_function_call(funccall_T *fc)
|
|||||||
listitem_T *li;
|
listitem_T *li;
|
||||||
int todo;
|
int todo;
|
||||||
dictitem_T *v;
|
dictitem_T *v;
|
||||||
|
static int made_copy = 0;
|
||||||
|
|
||||||
/* "fc" is still in use. This can happen when returning "a:000",
|
/* "fc" is still in use. This can happen when returning "a:000",
|
||||||
* assigning "l:" to a global variable or defining a closure.
|
* assigning "l:" to a global variable or defining a closure.
|
||||||
@@ -673,6 +674,16 @@ cleanup_function_call(funccall_T *fc)
|
|||||||
/* Make a copy of the a:000 items, since we didn't do that above. */
|
/* Make a copy of the a:000 items, since we didn't do that above. */
|
||||||
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
|
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
|
||||||
copy_tv(&li->li_tv, &li->li_tv);
|
copy_tv(&li->li_tv, &li->li_tv);
|
||||||
|
|
||||||
|
if (++made_copy == 10000)
|
||||||
|
{
|
||||||
|
// We have made a lot of copies. This can happen when
|
||||||
|
// repetitively calling a function that creates a reference to
|
||||||
|
// itself somehow. Call the garbage collector here to avoid using
|
||||||
|
// too much memory.
|
||||||
|
made_copy = 0;
|
||||||
|
(void)garbage_collect(FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -723,6 +734,8 @@ call_user_func(
|
|||||||
line_breakcheck(); /* check for CTRL-C hit */
|
line_breakcheck(); /* check for CTRL-C hit */
|
||||||
|
|
||||||
fc = (funccall_T *)alloc(sizeof(funccall_T));
|
fc = (funccall_T *)alloc(sizeof(funccall_T));
|
||||||
|
if (fc == NULL)
|
||||||
|
return;
|
||||||
fc->caller = current_funccal;
|
fc->caller = current_funccal;
|
||||||
current_funccal = fc;
|
current_funccal = fc;
|
||||||
fc->func = fp;
|
fc->func = fp;
|
||||||
|
@@ -791,6 +791,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 */
|
||||||
|
/**/
|
||||||
|
800,
|
||||||
/**/
|
/**/
|
||||||
799,
|
799,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user