Skip to content

Fix: memory leak in call_oc_method in src/vim9class.c#19828

Open
huanghuihui0904 wants to merge 1 commit intovim:masterfrom
huanghuihui0904:fix-memory-leak-call_oc_method
Open

Fix: memory leak in call_oc_method in src/vim9class.c#19828
huanghuihui0904 wants to merge 1 commit intovim:masterfrom
huanghuihui0904:fix-memory-leak-call_oc_method

Conversation

@huanghuihui0904
Copy link
Copy Markdown
Contributor

Problem

In call_oc_method() located in src/vim9class.c, get_func_arguments() is called at line 3100 to parse and evaluate function arguments into argvars[]. When get_func_arguments() fails, it may have already populated argvars[0..argcount-1] with evaluated arguments that own allocated memory (e.g., strings, lists, dicts).

The function returns FAIL immediately without cleaning up these arguments:

int ret = get_func_arguments(&argp, evalarg, 0, argvars, &argcount, FALSE);
if (ret == FAIL)
    return FAIL;       // argvars[0..argcount-1] leaked

The cleanup loop at lines 3126-3127 is only reached on the success path:

for (int idx = 0; idx < argcount; ++idx)
    clear_tv(&argvars[idx]);

Other callers of get_func_arguments() (e.g., get_func_tv() in src/userfunc.c:2209-2210) correctly clean up argvars on both success and failure paths.

Solution

Clean up the already-parsed arguments before returning FAIL, matching the pattern used in get_func_tv(). The fix is included in the commit.

Signed-off-by: huanghuihui0904 <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.

1 participant