]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2086: Memory leak when skipping invalid literal dict v9.1.2086
authorSean Dewar <6256228+seandewar@users.noreply.github.com>
Thu, 15 Jan 2026 20:14:08 +0000 (20:14 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 15 Jan 2026 20:14:08 +0000 (20:14 +0000)
Problem:  memory leak when not evaluating (just parsing) invalid literal
          dict.
Solution: Always clear the key's typval (Sean Dewar)

Though "check_typval_is_value(&tv) == FAIL && !evaluate" is maybe never
true, also always clear tvs if check_typval_is_value fails; at worst
this would be a no-op as their initial types are VAR_UNKNOWN.

closes: #19178

Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/dict.c
src/testdir/test_listdict.vim
src/version.c

index f539250af9b3d29e9bb3e26de39f94b985fa8d0b..0eb5a481aa9c319c3d090e2739bd17dd369c5ed1 100644 (file)
@@ -1038,17 +1038,13 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
        *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
        if (eval1(arg, &tv, evalarg) == FAIL)   // recursive!
        {
-           if (evaluate)
-               clear_tv(&tvkey);
+           clear_tv(&tvkey);
            goto failret;
        }
        if (check_typval_is_value(&tv) == FAIL)
        {
-           if (evaluate)
-           {
-               clear_tv(&tvkey);
-               clear_tv(&tv);
-           }
+           clear_tv(&tvkey);
+           clear_tv(&tv);
            goto failret;
        }
        if (evaluate)
index 4e22f63acd9938052bf13b6943f154e42130b923..316e3614fc8295152774c8613177aa11bf177ca5 100644 (file)
@@ -575,6 +575,8 @@ func Test_dict_literal_keys()
   " why *{} cannot be used for a literal dictionary
   let blue = 'blue'
   call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
+
+  call assert_fails('eval 1 || #{a:', 'E15:') " used to leak
 endfunc
 
 " Nasty: deepcopy() dict that refers to itself (fails when noref used)
index 3e3bae84b9ec027be2abc1d3854a8e124fffbe6f..b4e8e8a6dd4fec921e0b70cf44f3a0ad9fca9071 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2086,
 /**/
     2085,
 /**/