Skip to content

Fix memory leak in eval_dict() in src/dict.c#19531

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

Fix memory leak in eval_dict() in src/dict.c#19531
huanghuihui0904 wants to merge 1 commit intovim:masterfrom
huanghuihui0904:fix-memory-leak-eval_dict

Conversation

@huanghuihui0904
Copy link
Contributor

Problem

In eval_dict(), the dictionary d is allocated when evaluate is true (lines 958–963):

if (evaluate)
{
    d = dict_alloc();
    if (d == NULL)
        return FAIL;
}

Later, when parsing a Vim9 dictionary key written in bracket form ([key]), the code reports an error if the closing ] is missing and returns early (lines 993–998):

if (**arg != ']')
{
    emsg(_(e_missing_matching_bracket_after_dict_key));
    clear_tv(&tvkey);
    return FAIL;
}

Returning directly bypasses the shared cleanup in the failret: block, where d is freed. This results in a memory leak on this error path.

Solution

Replace the direct return FAIL; with goto failret; so that the existing cleanup logic is executed. The fix is included in this commit.

@chrisbra
Copy link
Member

thanks

@chrisbra chrisbra closed this in 525d1d6 Feb 28, 2026
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