Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few more leaks on failures #14517

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/autocmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3406,7 +3406,10 @@
event_dict = dict_alloc();
if (event_dict == NULL
|| list_append_dict(event_list, event_dict) == FAIL)
{
vim_free(pat);

Check warning on line 3410 in src/autocmd.c

View check run for this annotation

Codecov / codecov/patch

src/autocmd.c#L3410

Added line #L3410 was not covered by tests
return;
}

if (dict_add_string(event_dict, "event", event_name) == FAIL
|| dict_add_string(event_dict, "group",
Expand All @@ -3421,7 +3424,10 @@
|| dict_add_bool(event_dict, "once", ac->once) == FAIL
|| dict_add_bool(event_dict, "nested",
ac->nested) == FAIL)
{
vim_free(pat);

Check warning on line 3428 in src/autocmd.c

View check run for this annotation

Codecov / codecov/patch

src/autocmd.c#L3428

Added line #L3428 was not covered by tests
return;
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,12 +1300,18 @@ dict_extend_func(

action = tv_get_string_chk(&argvars[2]);
if (action == NULL)
{
if (is_new)
dict_unref(d1);
return;
}
for (i = 0; i < 3; ++i)
if (STRCMP(action, av[i]) == 0)
break;
if (i == 3)
{
if (is_new)
dict_unref(d1);
semsg(_(e_invalid_argument_str), action);
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/filepath.c
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,7 @@ f_resolve(typval_T *argvars, typval_T *rettv)
if (buf == NULL)
{
vim_free(p);
vim_free(remain);
goto fail;
}

Expand Down
3 changes: 3 additions & 0 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,10 @@
if ((d = dict_alloc()) == NULL)
return;
if (list_append_dict(rettv->vval.v_list, d) == FAIL)
{
dict_unref(d);

Check warning on line 2578 in src/map.c

View check run for this annotation

Codecov / codecov/patch

src/map.c#L2578

Added line #L2578 was not covered by tests
return;
}

keys_buf = NULL;
did_simplify = FALSE;
Expand Down
3 changes: 3 additions & 0 deletions src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,10 @@ set_string_default_esc(char *name, char_u *val, int escape)

opt_idx = findoption((char_u *)name);
if (opt_idx < 0)
{
vim_free(p);
return;
}

if (options[opt_idx].flags & P_DEF_ALLOCED)
vim_free(options[opt_idx].def_val[VI_DEFAULT]);
Expand Down
6 changes: 6 additions & 0 deletions src/testdir/test_listdict.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1530,4 +1530,10 @@ func Test_indexof()
delfunc TestIdx
endfunc

func Test_extendnew_leak()
" This used to leak memory
for i in range(100) | silent! call extendnew([], [], []) | endfor
for i in range(100) | silent! call extendnew({}, {}, {}) | endfor
endfunc

" vim: shiftwidth=2 sts=2 expandtab