Skip to content

Commit f648854

Browse files
committed
patch 8.2.3180: Vim9: memory leak when concatenating to an imported string
Problem: Vim9: memory leak when concatenating to an imported string. Solution: Clear the destination.
1 parent 24e9316 commit f648854

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/evalvars.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,7 @@ set_var_const(
32623262
// TODO: check the type
32633263
// TODO: check for const and locked
32643264
dest_tv = sv->sv_tv;
3265+
clear_tv(dest_tv);
32653266
}
32663267
}
32673268

@@ -3272,12 +3273,13 @@ set_var_const(
32723273
di = find_var_in_scoped_ht(name, TRUE);
32733274

32743275
if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
3275-
&& var_wrong_func_name(name, di == NULL))
3276+
&& var_wrong_func_name(name, di == NULL))
32763277
goto failed;
32773278

32783279
if (need_convert_to_bool(type, tv))
32793280
{
3280-
// Destination is a bool and the value is not, but it can be converted.
3281+
// Destination is a bool and the value is not, but it can be
3282+
// converted.
32813283
CLEAR_FIELD(bool_tv);
32823284
bool_tv.v_type = VAR_BOOL;
32833285
bool_tv.vval.v_number = tv2bool(tv) ? VVAL_TRUE : VVAL_FALSE;
@@ -3290,14 +3292,14 @@ set_var_const(
32903292
if ((di->di_flags & DI_FLAGS_RELOAD) == 0)
32913293
{
32923294
if ((flags & (ASSIGN_CONST | ASSIGN_FINAL))
3293-
&& (flags & ASSIGN_FOR_LOOP) == 0)
3295+
&& (flags & ASSIGN_FOR_LOOP) == 0)
32943296
{
32953297
emsg(_(e_cannot_mod));
32963298
goto failed;
32973299
}
32983300

32993301
if (is_script_local && vim9script
3300-
&& (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0)
3302+
&& (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0)
33013303
{
33023304
semsg(_(e_redefining_script_item_str), name);
33033305
goto failed;
@@ -3310,7 +3312,8 @@ set_var_const(
33103312
// check the type and adjust to bool if needed
33113313
where.wt_index = var_idx;
33123314
where.wt_variable = TRUE;
3313-
if (check_script_var_type(&di->di_tv, tv, name, where) == FAIL)
3315+
if (check_script_var_type(&di->di_tv, tv, name, where)
3316+
== FAIL)
33143317
goto failed;
33153318
}
33163319

@@ -3322,11 +3325,11 @@ set_var_const(
33223325
// can only redefine once
33233326
di->di_flags &= ~DI_FLAGS_RELOAD;
33243327

3325-
// A Vim9 script-local variable is also present in sn_all_vars and
3326-
// sn_var_vals. It may set "type" from "tv".
3328+
// A Vim9 script-local variable is also present in sn_all_vars
3329+
// and sn_var_vals. It may set "type" from "tv".
33273330
if (var_in_vim9script)
33283331
update_vim9_script_var(FALSE, di, flags, tv, &type,
3329-
(flags & ASSIGN_NO_MEMBER_TYPE) == 0);
3332+
(flags & ASSIGN_NO_MEMBER_TYPE) == 0);
33303333
}
33313334

33323335
// existing variable, need to clear the value
@@ -3342,8 +3345,9 @@ set_var_const(
33423345
{
33433346
char_u *val = tv_get_string(tv);
33443347

3345-
// Careful: when assigning to v:errmsg and tv_get_string()
3346-
// causes an error message the variable will already be set.
3348+
// Careful: when assigning to v:errmsg and
3349+
// tv_get_string() causes an error message the variable
3350+
// will already be set.
33473351
if (di->di_tv.vval.v_string == NULL)
33483352
di->di_tv.vval.v_string = vim_strsave(val);
33493353
}
@@ -3359,7 +3363,8 @@ set_var_const(
33593363
{
33603364
di->di_tv.vval.v_number = tv_get_number(tv);
33613365
if (STRCMP(varname, "searchforward") == 0)
3362-
set_search_direction(di->di_tv.vval.v_number ? '/' : '?');
3366+
set_search_direction(di->di_tv.vval.v_number
3367+
? '/' : '?');
33633368
#ifdef FEAT_SEARCH_EXTRA
33643369
else if (STRCMP(varname, "hlsearch") == 0)
33653370
{
@@ -3382,7 +3387,7 @@ set_var_const(
33823387
{
33833388
// Item not found, check if a function already exists.
33843389
if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0
3385-
&& lookup_scriptitem(name, STRLEN(name), FALSE, NULL) == OK)
3390+
&& lookup_scriptitem(name, STRLEN(name), FALSE, NULL) == OK)
33863391
{
33873392
semsg(_(e_redefining_script_item_str), name);
33883393
goto failed;
@@ -3405,7 +3410,7 @@ set_var_const(
34053410
// Make sure the variable name is valid. In Vim9 script an autoload
34063411
// variable must be prefixed with "g:".
34073412
if (!valid_varname(varname, !vim9script
3408-
|| STRNCMP(name, "g:", 2) == 0))
3413+
|| STRNCMP(name, "g:", 2) == 0))
34093414
goto failed;
34103415

34113416
di = alloc(sizeof(dictitem_T) + STRLEN(varname));
@@ -3425,7 +3430,7 @@ set_var_const(
34253430
// sn_var_vals. It may set "type" from "tv".
34263431
if (var_in_vim9script)
34273432
update_vim9_script_var(TRUE, di, flags, tv, &type,
3428-
(flags & ASSIGN_NO_MEMBER_TYPE) == 0);
3433+
(flags & ASSIGN_NO_MEMBER_TYPE) == 0);
34293434
}
34303435

34313436
dest_tv = &di->di_tv;

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+
3180,
758760
/**/
759761
3179,
760762
/**/

0 commit comments

Comments
 (0)