# HG changeset patch # User Bram Moolenaar # Date 1628175603 -7200 # Node ID d84f6784c27cff147f77a184b9b823ff858da0d9 # Parent bb806540f72ebacff2e7e9e9da3d15716839c3f5 patch 8.2.3294: Lua: memory leak when adding dict item fails Commit: https://github.com/vim/vim/commit/1b6acf02b7e685ecb87ccba52c91835a7519073e Author: Bram Moolenaar Date: Thu Aug 5 16:47:08 2021 +0200 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. diff --git a/src/if_lua.c b/src/if_lua.c --- a/src/if_lua.c +++ b/src/if_lua.c @@ -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); diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3294, +/**/ 3293, /**/ 3292,