Skip to content

Fix memory leak in expand_findfunc() in src/ex_docmd.c#19564

Closed
huanghuihui0904 wants to merge 1 commit intovim:masterfrom
huanghuihui0904:fix-memory-leak-expand_findfunc
Closed

Fix memory leak in expand_findfunc() in src/ex_docmd.c#19564
huanghuihui0904 wants to merge 1 commit intovim:masterfrom
huanghuihui0904:fix-memory-leak-expand_findfunc

Conversation

@huanghuihui0904
Copy link
Contributor

Problem

In expand_findfunc(), the list l is allocated by call_findfunc() (lines 7076–7079):

l = call_findfunc(pat, VVAL_TRUE);

if (l == NULL)
    return FAIL;

However, there are early-return paths after l is allocated (lines 7081–7087):

len = list_len(l);
if (len == 0)        // empty List
    return FAIL;

*files = ALLOC_MULT(char_u *, len);
if (*files == NULL)
    return FAIL;

On these failure paths, l is not freed. Since list_free(l) is only called on the success path near the end of the function, l is leaked when returning early.

Solution

Free l before returning on error paths. The fix is included in this commit.

Signed-off-by: huanghuihui0904 <625173@qq.com>
@chrisbra
Copy link
Member

chrisbra commented Mar 3, 2026

thanks

@chrisbra chrisbra closed this in 648240f Mar 3, 2026
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Mar 4, 2026
Problem:  memory leak in expand_findfunc() (after v9.1.0811)
Solution: Free list variable l on early return (Huihui Huang).

closes: vim/vim#19564

vim/vim@648240f

N/A patches:
vim-patch:9.2.0105: memory leak in heredoc_get() in src/evalvars.c

Co-authored-by: Huihui Huang <625173@qq.com>
ZieMcd pushed a commit to ZieMcd/neovim that referenced this pull request Mar 6, 2026
Problem:  memory leak in expand_findfunc() (after v9.1.0811)
Solution: Free list variable l on early return (Huihui Huang).

closes: vim/vim#19564

vim/vim@648240f

N/A patches:
vim-patch:9.2.0105: memory leak in heredoc_get() in src/evalvars.c

Co-authored-by: Huihui Huang <625173@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants