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>
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;
}
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 813,
/**/
812,
/**/