Skip to content

Commit 13e1af7

Browse files
brandb97chrisbra
authored andcommitted
patch 9.1.1580: possible memory leak in vim9type.c
Problem: possible memory leak in vim9type.c Solution: Free tuple_types_ga if there was an error in type_type_add_types() (Lidong Yan) In parse_type_tuple() at src/vim9type.c, we allocate memory in `tuple_types_ga` by ga_grow(), but forget to free it when tuple_type_add_types() fails. Replace `return NULL` with `goto on_err` to fix leak. closes: #17820 Signed-off-by: Lidong Yan <yldhome2d2@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7cf31ce commit 13e1af7

2 files changed

Lines changed: 6 additions & 2 deletions

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+
1580,
722724
/**/
723725
1579,
724726
/**/

src/vim9type.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,8 +1886,10 @@ parse_type_tuple(
18861886
ret_type = alloc_tuple_type(typecount, type_gap);
18871887
ret_type->tt_flags = flags;
18881888
ret_type->tt_argcount = typecount;
1889-
if (tuple_type_add_types(ret_type, typecount, type_gap) == FAIL)
1890-
return NULL;
1889+
if (tuple_type_add_types(ret_type, typecount, type_gap) == FAIL) {
1890+
ret_type = NULL;
1891+
goto on_err;
1892+
}
18911893
mch_memmove(ret_type->tt_args, tuple_types_ga.ga_data,
18921894
sizeof(type_T *) * typecount);
18931895

0 commit comments

Comments
 (0)