Skip to content

Commit 29269a7

Browse files
committed
patch 9.1.0341: Problem: a few memory leaks are found
Problem: a few memory leaks are found (LuMingYinDetect ) Solution: properly free the memory Fixes the following problems: - Memory leak in f_maplist() fixes: #14486 - Memory leak in option.c fixes: #14485 - Memory leak in f_resolve() fixes: #14484 - Memory leak in f_autocmd_get() related: #14474 - Memory leak in dict_extend_func() fixes: #14477 fixes: #14238 closes: #14517 Signed-off-by: Christian Brabandt <[email protected]>
1 parent f7d31ad commit 29269a7

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

src/autocmd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,7 +3406,10 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv)
34063406
event_dict = dict_alloc();
34073407
if (event_dict == NULL
34083408
|| list_append_dict(event_list, event_dict) == FAIL)
3409+
{
3410+
vim_free(pat);
34093411
return;
3412+
}
34103413

34113414
if (dict_add_string(event_dict, "event", event_name) == FAIL
34123415
|| dict_add_string(event_dict, "group",
@@ -3421,7 +3424,10 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv)
34213424
|| dict_add_bool(event_dict, "once", ac->once) == FAIL
34223425
|| dict_add_bool(event_dict, "nested",
34233426
ac->nested) == FAIL)
3427+
{
3428+
vim_free(pat);
34243429
return;
3430+
}
34253431
}
34263432
}
34273433
}

src/dict.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,18 @@ dict_extend_func(
13001300

13011301
action = tv_get_string_chk(&argvars[2]);
13021302
if (action == NULL)
1303+
{
1304+
if (is_new)
1305+
dict_unref(d1);
13031306
return;
1307+
}
13041308
for (i = 0; i < 3; ++i)
13051309
if (STRCMP(action, av[i]) == 0)
13061310
break;
13071311
if (i == 3)
13081312
{
1313+
if (is_new)
1314+
dict_unref(d1);
13091315
semsg(_(e_invalid_argument_str), action);
13101316
return;
13111317
}

src/filepath.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,7 @@ f_resolve(typval_T *argvars, typval_T *rettv)
21102110
if (buf == NULL)
21112111
{
21122112
vim_free(p);
2113+
vim_free(remain);
21132114
goto fail;
21142115
}
21152116

src/map.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,10 @@ f_maplist(typval_T *argvars UNUSED, typval_T *rettv)
25742574
if ((d = dict_alloc()) == NULL)
25752575
return;
25762576
if (list_append_dict(rettv->vval.v_list, d) == FAIL)
2577+
{
2578+
dict_unref(d);
25772579
return;
2580+
}
25782581

25792582
keys_buf = NULL;
25802583
did_simplify = FALSE;

src/option.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,10 @@ set_string_default_esc(char *name, char_u *val, int escape)
853853

854854
opt_idx = findoption((char_u *)name);
855855
if (opt_idx < 0)
856+
{
857+
vim_free(p);
856858
return;
859+
}
857860

858861
if (options[opt_idx].flags & P_DEF_ALLOCED)
859862
vim_free(options[opt_idx].def_val[VI_DEFAULT]);

src/testdir/test_listdict.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,4 +1530,10 @@ func Test_indexof()
15301530
delfunc TestIdx
15311531
endfunc
15321532

1533+
func Test_extendnew_leak()
1534+
" This used to leak memory
1535+
for i in range(100) | silent! call extendnew([], [], []) | endfor
1536+
for i in range(100) | silent! call extendnew({}, {}, {}) | endfor
1537+
endfunc
1538+
15331539
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
341,
707709
/**/
708710
340,
709711
/**/

0 commit comments

Comments
 (0)