Patch 8.2.1669
Problem: Vim9: memory leak when storing a value fails.
Solution: Free the value when not storing it.
Files: src/evalvars.c
*** ../vim-8.2.1668/src/evalvars.c 2020-09-09 22:27:55.425537078 +0200
--- src/evalvars.c 2020-09-12 19:41:41.034854325 +0200
***************
*** 2950,2956 ****
if (ht == NULL || *varname == NUL)
{
semsg(_(e_illvar), name);
! return;
}
is_script_local = ht == get_script_local_ht();
--- 2950,2956 ----
if (ht == NULL || *varname == NUL)
{
semsg(_(e_illvar), name);
! goto failed;
}
is_script_local = ht == get_script_local_ht();
***************
*** 2960,2966 ****
&& name[1] == ':')
{
vim9_declare_error(name);
! return;
}
di = find_var_in_ht(ht, 0, varname, TRUE);
--- 2960,2966 ----
&& name[1] == ':')
{
vim9_declare_error(name);
! goto failed;
}
di = find_var_in_ht(ht, 0, varname, TRUE);
***************
*** 2971,2977 ****
if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
&& var_wrong_func_name(name, di == NULL))
! return;
if (need_convert_to_bool(type, tv))
{
--- 2971,2977 ----
if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
&& var_wrong_func_name(name, di == NULL))
! goto failed;
if (need_convert_to_bool(type, tv))
{
***************
*** 2989,2995 ****
if (flags & LET_IS_CONST)
{
emsg(_(e_cannot_mod));
! return;
}
if (is_script_local && in_vim9script())
--- 2989,2995 ----
if (flags & LET_IS_CONST)
{
emsg(_(e_cannot_mod));
! goto failed;
}
if (is_script_local && in_vim9script())
***************
*** 2997,3013 ****
if ((flags & LET_NO_COMMAND) == 0)
{
semsg(_(e_redefining_script_item_str), name);
! return;
}
// check the type and adjust to bool if needed
if (check_script_var_type(&di->di_tv, tv, name) == FAIL)
! return;
}
if (var_check_ro(di->di_flags, name, FALSE)
|| var_check_lock(di->di_tv.v_lock, name, FALSE))
! return;
}
else
// can only redefine once
--- 2997,3013 ----
if ((flags & LET_NO_COMMAND) == 0)
{
semsg(_(e_redefining_script_item_str), name);
! goto failed;
}
// check the type and adjust to bool if needed
if (check_script_var_type(&di->di_tv, tv, name) == FAIL)
! goto failed;
}
if (var_check_ro(di->di_flags, name, FALSE)
|| var_check_lock(di->di_tv.v_lock, name, FALSE))
! goto failed;
}
else
// can only redefine once
***************
*** 3037,3043 ****
di->di_tv.vval.v_string = tv->vval.v_string;
tv->vval.v_string = NULL;
}
! return;
}
else if (di->di_tv.v_type == VAR_NUMBER)
{
--- 3037,3043 ----
di->di_tv.vval.v_string = tv->vval.v_string;
tv->vval.v_string = NULL;
}
! goto failed;
}
else if (di->di_tv.v_type == VAR_NUMBER)
{
***************
*** 3051,3062 ****
redraw_all_later(SOME_VALID);
}
#endif
! return;
}
else if (di->di_tv.v_type != tv->v_type)
{
semsg(_("E963: setting %s to value with wrong type"), name);
! return;
}
}
--- 3051,3062 ----
redraw_all_later(SOME_VALID);
}
#endif
! goto failed;
}
else if (di->di_tv.v_type != tv->v_type)
{
semsg(_("E963: setting %s to value with wrong type"), name);
! goto failed;
}
}
***************
*** 3068,3088 ****
if (ht == &vimvarht || ht == get_funccal_args_ht())
{
semsg(_(e_illvar), name);
! return;
}
// Make sure the variable name is valid.
if (!valid_varname(varname))
! return;
di = alloc(sizeof(dictitem_T) + STRLEN(varname));
if (di == NULL)
! return;
STRCPY(di->di_key, varname);
if (hash_add(ht, DI2HIKEY(di)) == FAIL)
{
vim_free(di);
! return;
}
di->di_flags = DI_FLAGS_ALLOC;
if (flags & LET_IS_CONST)
--- 3068,3088 ----
if (ht == &vimvarht || ht == get_funccal_args_ht())
{
semsg(_(e_illvar), name);
! goto failed;
}
// Make sure the variable name is valid.
if (!valid_varname(varname))
! goto failed;
di = alloc(sizeof(dictitem_T) + STRLEN(varname));
if (di == NULL)
! goto failed;
STRCPY(di->di_key, varname);
if (hash_add(ht, DI2HIKEY(di)) == FAIL)
{
vim_free(di);
! goto failed;
}
di->di_flags = DI_FLAGS_ALLOC;
if (flags & LET_IS_CONST)
***************
*** 3128,3133 ****
--- 3128,3137 ----
// if the reference count is up to one. That locks only literal
// values.
item_lock(&di->di_tv, DICT_MAXNEST, TRUE, TRUE);
+ return;
+ failed:
+ if (!copy)
+ clear_tv(tv_arg);
}
/*
*** ../vim-8.2.1668/src/version.c 2020-09-12 19:11:19.675415067 +0200
--- src/version.c 2020-09-12 19:39:51.159167348 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1669,
/**/
--
You can be stopped by the police for biking over 65 miles per hour.
You are not allowed to walk across a street on your hands.
[real standing laws in Connecticut, United States of America]
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202009121752.08CHq7FP1188018%40masaka.moolenaar.net.