]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0813: dict_add_func() may corrupt funcref count on failure v9.2.0813
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Mon, 20 Jul 2026 16:02:56 +0000 (16:02 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 20 Jul 2026 16:02:56 +0000 (16:02 +0000)
Problem:  dict_add_func() references the function only after a
          successful dict_add(), on failure dictitem_free()
          calls func_unref() without a matching func_ref(), corrupting
          the reference count of a lambda or numbered function.
Solution: Take the reference before dict_add() so the unref on the
          failure path is balanced (Yasuhiro Matsumoto).

related: #20668
closes:  #20742

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/dict.c
src/version.c

index ac1fb3841b48b5a080ee9a07b5633b89c705ae94..5531cc72a097b61cc100ac76ab480ff31c155248 100644 (file)
@@ -552,12 +552,13 @@ dict_add_func(dict_T *d, char *key, ufunc_T *fp)
        return FAIL;
     item->di_tv.v_type = VAR_FUNC;
     item->di_tv.vval.v_string = vim_strnsave(fp->uf_name, fp->uf_namelen);
+    // Reference before dict_add() so dictitem_free()'s unref stays balanced on failure.
+    func_ref(item->di_tv.vval.v_string);
     if (dict_add(d, item) == FAIL)
     {
        dictitem_free(item);
        return FAIL;
     }
-    func_ref(item->di_tv.vval.v_string);
     return OK;
 }
 
index 333bbc87d8b3f8ba65b7d7d360949e2e9568cc37..178090f6b16ac0666fdb30906fab18587b3d382d 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    813,
 /**/
     812,
 /**/