0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.1332: Vim9: memory leak when using nested global function

Problem:    Vim9: memory leak when using nested global function.
Solution:   Delete the function when deleting the instruction.  Disable test
            that still causes a leak.
This commit is contained in:
Bram Moolenaar
2020-07-31 23:47:12 +02:00
parent badd8486f7
commit ce6583568f
5 changed files with 49 additions and 25 deletions

View File

@@ -780,7 +780,7 @@ find_func_with_sid(char_u *name, int sid)
* When "is_global" is true don't find script-local or imported functions.
* Return NULL for unknown function.
*/
static ufunc_T *
ufunc_T *
find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
{
hashitem_T *hi;
@@ -1759,7 +1759,7 @@ delete_script_functions(int sid)
{
hashitem_T *hi;
ufunc_T *fp;
long_u todo;
long_u todo = 1;
char_u buf[30];
size_t len;
@@ -1769,18 +1769,27 @@ delete_script_functions(int sid)
sprintf((char *)buf + 3, "%d_", sid);
len = STRLEN(buf);
todo = func_hashtab.ht_used;
for (hi = func_hashtab.ht_array; todo > 0; ++hi)
if (!HASHITEM_EMPTY(hi))
{
fp = HI2UF(hi);
if (STRNCMP(fp->uf_name, buf, len) == 0)
while (todo > 0)
{
todo = func_hashtab.ht_used;
for (hi = func_hashtab.ht_array; todo > 0; ++hi)
if (!HASHITEM_EMPTY(hi))
{
fp->uf_flags |= FC_DEAD;
func_clear(fp, TRUE);
fp = HI2UF(hi);
if (STRNCMP(fp->uf_name, buf, len) == 0)
{
int changed = func_hashtab.ht_changed;
fp->uf_flags |= FC_DEAD;
func_clear(fp, TRUE);
// When clearing a function another function can be cleared
// as a side effect. When that happens start over.
if (changed != func_hashtab.ht_changed)
break;
}
--todo;
}
--todo;
}
}
}
#if defined(EXITFREE) || defined(PROTO)