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>
This commit is contained in:
Lidong Yan
2025-07-22 18:11:11 +02:00
committed by Christian Brabandt
parent 7cf31ce9c4
commit 13e1af7de9
2 changed files with 6 additions and 2 deletions

View File

@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1580,
/**/
1579,
/**/

View File

@ -1886,8 +1886,10 @@ parse_type_tuple(
ret_type = alloc_tuple_type(typecount, type_gap);
ret_type->tt_flags = flags;
ret_type->tt_argcount = typecount;
if (tuple_type_add_types(ret_type, typecount, type_gap) == FAIL)
return NULL;
if (tuple_type_add_types(ret_type, typecount, type_gap) == FAIL) {
ret_type = NULL;
goto on_err;
}
mch_memmove(ret_type->tt_args, tuple_types_ga.ga_data,
sizeof(type_T *) * typecount);