]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0773: Memory leak in evalfunc.c on alloc failure v9.2.0773
authorChristian Brabandt <cb@256bit.org>
Thu, 2 Jul 2026 19:38:26 +0000 (19:38 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 2 Jul 2026 19:39:38 +0000 (19:39 +0000)
Problem:  Memory leak in evalfunc.c on alloc failure
Solution: Call dict_unref() when list_append_dict() fails before
          returning.

related: #20668

Supported by AI.

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/evalfunc.c
src/version.c

index 3aeda7e11b19f87ba57487e393606afd15fa8b03..15b1eee8738629c151535bd7dbcf675d5e053c56 100644 (file)
@@ -5840,7 +5840,10 @@ f_getchangelist(typval_T *argvars, typval_T *rettv)
        if ((d = dict_alloc()) == NULL)
            return;
        if (list_append_dict(l, d) == FAIL)
+       {
+           dict_unref(d);
            return;
+       }
        dict_add_number(d, "lnum", (long)buf->b_changelist[i].lnum);
        dict_add_number(d, "col", (long)buf->b_changelist[i].col);
        dict_add_number(d, "coladd", (long)buf->b_changelist[i].coladd);
@@ -6058,7 +6061,10 @@ f_getjumplist(typval_T *argvars, typval_T *rettv)
        if ((d = dict_alloc()) == NULL)
            return;
        if (list_append_dict(l, d) == FAIL)
+       {
+           dict_unref(d);
            return;
+       }
        dict_add_number(d, "lnum", (long)wp->w_jumplist[i].fmark.mark.lnum);
        dict_add_number(d, "col", (long)wp->w_jumplist[i].fmark.mark.col);
        dict_add_number(d, "coladd", (long)wp->w_jumplist[i].fmark.mark.coladd);
@@ -9498,7 +9504,10 @@ get_matches_in_str(
        if (d == NULL)
            return FAIL;
        if (list_append_dict(mlist, d) == FAIL)
+       {
+           dict_unref(d);
            return FAIL;
+       }
 
        if (dict_add_number(d, matchbuf ? "lnum" : "idx", idx) == FAIL)
            return FAIL;
@@ -9518,7 +9527,10 @@ get_matches_in_str(
                return FAIL;
 
            if (dict_add_list(d, "submatches", sml) == FAIL)
+           {
+               list_unref(sml);
                return FAIL;
+           }
 
            // return a list with the submatches
            for (int i = 1; i < NSUBEXP; ++i)
index 2c4e9cf24c94ab60369de45771da93a04181c533..7e0fe9136037ed33c5f7375ab662ac043376e8b1 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    773,
 /**/
     772,
 /**/