]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1581: possible memory leak in vim9generics.c v9.1.1581
authorLidong Yan <yldhome2d2@gmail.com>
Tue, 22 Jul 2025 16:15:57 +0000 (18:15 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 22 Jul 2025 16:15:57 +0000 (18:15 +0200)
Problem:  possible memory leak in vim9generics.c
Solution: Free ret_free if ga_grow() fails and before returning
          (Lidong Yan).

In parse_generic_func_type_args() at vim9generics.c, we allocate memory
in ret_name and should free it by calling vim_free(ret_free). If
ga_grow on gfatab->gfat_args failed, we forget to call vim_free(ret_free)
thus would cause a leak. Add vim_free(ret_free) before return NULL.

closes: #17821

Signed-off-by: Lidong Yan <yldhome2d2@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/version.c
src/vim9generics.c

index fa2ebcda9855ad61fb67db5af54d458c75110b37..9a371ef2c01f8e50714fef74f197a3887659601f 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1581,
 /**/
     1580,
 /**/
index 1452610a3f6bafb7ddd715cf20998b73df2621ca..fc45af73cd8225adfecb4d1fdb6c809ace56453c 100644 (file)
@@ -305,8 +305,10 @@ parse_generic_func_type_args(
        char    *ret_name = type_name(type_arg, &ret_free);
 
        // create space for the name and the new type
-       if (ga_grow(&gfatab->gfat_args, 1) == FAIL)
+       if (ga_grow(&gfatab->gfat_args, 1) == FAIL) {
+           vim_free(ret_free);
            return NULL;
+       }
        generic_arg = (generic_T *)gfatab->gfat_args.ga_data +
                                                gfatab->gfat_args.ga_len;
        gfatab->gfat_args.ga_len++;