0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.3294: Lua: memory leak when adding dict item fails

Problem:    Lua: memory leak when adding dict item fails.
Solution:   Free the typval and the dict item.
This commit is contained in:
Bram Moolenaar 2021-08-05 16:47:08 +02:00
parent 6a230c6b32
commit 1b6acf02b7
2 changed files with 11 additions and 1 deletions

View File

@ -1859,12 +1859,20 @@ luaV_setvar(lua_State *L)
// Need to create an entry // Need to create an entry
di = dictitem_alloc((char_u *)name); di = dictitem_alloc((char_u *)name);
if (di == NULL) if (di == NULL)
{
clear_tv(&tv);
return 0; return 0;
}
// Update the value // Update the value
copy_tv(&tv, &di->di_tv); copy_tv(&tv, &di->di_tv);
if (dict_add(dict, di) == FAIL) if (dict_add(dict, di) == FAIL)
{
dictitem_free(di);
clear_tv(&tv);
return luaL_error(L, "Couldn't add to dictionary"); return luaL_error(L, "Couldn't add to dictionary");
} else }
}
else
{ {
// Clear the old value // Clear the old value
clear_tv(&di->di_tv); clear_tv(&di->di_tv);

View File

@ -755,6 +755,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 */
/**/
3294,
/**/ /**/
3293, 3293,
/**/ /**/