]> granicus.if.org Git - vim/commitdiff
patch 8.2.3429: leaking memory when assigning to list or dict v8.2.3429
authorBram Moolenaar <Bram@vim.org>
Sat, 11 Sep 2021 21:07:44 +0000 (23:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 11 Sep 2021 21:07:44 +0000 (23:07 +0200)
Problem:    Leaking memory when assigning to list or dict.
Solution:   Free the list or dict type before overwriting it.

src/evalvars.c
src/version.c
src/vim9type.c

index 5a26effbb31690d5d83104d6b4d63f37b1314eca..4cc0fa8e34e4c6f323c34785c5f1e37946e07077 100644 (file)
@@ -3462,9 +3462,21 @@ set_var_const(
     if (vim9script && type != NULL)
     {
        if (type->tt_type == VAR_DICT && dest_tv->vval.v_dict != NULL)
-           dest_tv->vval.v_dict->dv_type = alloc_type(type);
+       {
+           if (dest_tv->vval.v_dict->dv_type != type)
+           {
+               free_type(dest_tv->vval.v_dict->dv_type);
+               dest_tv->vval.v_dict->dv_type = alloc_type(type);
+           }
+       }
        else if (type->tt_type == VAR_LIST && dest_tv->vval.v_list != NULL)
-           dest_tv->vval.v_list->lv_type = alloc_type(type);
+       {
+           if (dest_tv->vval.v_list->lv_type != type)
+           {
+               free_type(dest_tv->vval.v_list->lv_type);
+               dest_tv->vval.v_list->lv_type = alloc_type(type);
+           }
+       }
     }
 
     // ":const var = value" locks the value
index 2d6f6c7bfd33ca98038e7dc08ee818f8f5e39731..d10f8aabb04d6903574389624fa02f955d74ce11 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3429,
 /**/
     3428,
 /**/
index c14b97fad3c47589efdb39826ad283d01ea37d58..b9e9b27ad1be78e20ad0710369c64d8fd2d0b6b8 100644 (file)
@@ -258,7 +258,7 @@ func_type_add_arg_types(
 typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
 {
     type_T  *type;
-    type_T  *member_type = &t_any;
+    type_T  *member_type = NULL;
     int            argcount = 0;
     int            min_argcount = 0;
 
@@ -268,6 +268,8 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
        return &t_bool;
     if (tv->v_type == VAR_STRING)
        return &t_string;
+    if (tv->v_type == VAR_BLOB)
+       return &t_blob;
 
     if (tv->v_type == VAR_LIST)
     {