Skip to content

Commit 9719452

Browse files
brandb97chrisbra
authored andcommitted
patch 9.1.1581: possible memory leak in vim9generics.c
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>
1 parent 13e1af7 commit 9719452

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1581,
722724
/**/
723725
1580,
724726
/**/

src/vim9generics.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,10 @@ parse_generic_func_type_args(
305305
char *ret_name = type_name(type_arg, &ret_free);
306306

307307
// create space for the name and the new type
308-
if (ga_grow(&gfatab->gfat_args, 1) == FAIL)
308+
if (ga_grow(&gfatab->gfat_args, 1) == FAIL) {
309+
vim_free(ret_free);
309310
return NULL;
311+
}
310312
generic_arg = (generic_T *)gfatab->gfat_args.ga_data +
311313
gfatab->gfat_args.ga_len;
312314
gfatab->gfat_args.ga_len++;

0 commit comments

Comments
 (0)