Skip to content

Commit 464393a

Browse files
committed
patch 8.2.3429: leaking memory when assigning to list or dict
Problem: Leaking memory when assigning to list or dict. Solution: Free the list or dict type before overwriting it.
1 parent 35a9a00 commit 464393a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/evalvars.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,9 +3462,21 @@ set_var_const(
34623462
if (vim9script && type != NULL)
34633463
{
34643464
if (type->tt_type == VAR_DICT && dest_tv->vval.v_dict != NULL)
3465-
dest_tv->vval.v_dict->dv_type = alloc_type(type);
3465+
{
3466+
if (dest_tv->vval.v_dict->dv_type != type)
3467+
{
3468+
free_type(dest_tv->vval.v_dict->dv_type);
3469+
dest_tv->vval.v_dict->dv_type = alloc_type(type);
3470+
}
3471+
}
34663472
else if (type->tt_type == VAR_LIST && dest_tv->vval.v_list != NULL)
3467-
dest_tv->vval.v_list->lv_type = alloc_type(type);
3473+
{
3474+
if (dest_tv->vval.v_list->lv_type != type)
3475+
{
3476+
free_type(dest_tv->vval.v_list->lv_type);
3477+
dest_tv->vval.v_list->lv_type = alloc_type(type);
3478+
}
3479+
}
34683480
}
34693481

34703482
// ":const var = value" locks the value

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3429,
758760
/**/
759761
3428,
760762
/**/

src/vim9type.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func_type_add_arg_types(
258258
typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
259259
{
260260
type_T *type;
261-
type_T *member_type = &t_any;
261+
type_T *member_type = NULL;
262262
int argcount = 0;
263263
int min_argcount = 0;
264264

@@ -268,6 +268,8 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
268268
return &t_bool;
269269
if (tv->v_type == VAR_STRING)
270270
return &t_string;
271+
if (tv->v_type == VAR_BLOB)
272+
return &t_blob;
271273

272274
if (tv->v_type == VAR_LIST)
273275
{

0 commit comments

Comments
 (0)