diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-09-11 23:07:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-09-11 23:07:44 +0200 |
commit | 464393a6961d9b9de2bfe9c05f8e2ae5bdec0293 (patch) | |
tree | 1b130816e331e9fc087db460e19aa99de55fd797 /src/evalvars.c | |
parent | 35a9a00afcb20897d462a766793ff45534810dc3 (diff) |
patch 8.2.3429: leaking memory when assigning to list or dictv8.2.3429
Problem: Leaking memory when assigning to list or dict.
Solution: Free the list or dict type before overwriting it.
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 5a26effbb3..4cc0fa8e34 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -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 |