]> granicus.if.org Git - vim/commitdiff
patch 8.2.3294: Lua: memory leak when adding dict item fails v8.2.3294
authorBram Moolenaar <Bram@vim.org>
Thu, 5 Aug 2021 14:47:08 +0000 (16:47 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 Aug 2021 14:47:08 +0000 (16:47 +0200)
Problem:    Lua: memory leak when adding dict item fails.
Solution:   Free the typval and the dict item.

src/if_lua.c
src/version.c

index 144fcbea5f9ed5863a1776ec0ac7ee22e0356abc..6ac39511221620a551d4a85c6c090e68c7434573 100644 (file)
@@ -1859,12 +1859,20 @@ luaV_setvar(lua_State *L)
            // Need to create an entry
            di = dictitem_alloc((char_u *)name);
            if (di == NULL)
+           {
+               clear_tv(&tv);
                return 0;
+           }
            // Update the value
            copy_tv(&tv, &di->di_tv);
            if (dict_add(dict, di) == FAIL)
+           {
+               dictitem_free(di);
+               clear_tv(&tv);
                return luaL_error(L, "Couldn't add to dictionary");
-       } else
+           }
+       }
+       else
        {
            // Clear the old value
            clear_tv(&di->di_tv);
index 2db7988ce2c6a784502ecec74a8f470300ca702d..c2d3998add3f3905f8c4966cc0cbd0694c677fd2 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3294,
 /**/
     3293,
 /**/