builtin/submodule--helper: fix leak when remote_submodule_branch() failed
PATCH 1/1 builtin/submodule--helper: fix leak when remote_submodule_branch() failed
From: Lidong Yan <[email protected]>
In builtin/submodule--helper.c:update_submodule(), the variable remote_name is allocated in get_default_remote_submodule() but may be leaked if remote_submodule_branch() fails. Although it is unlikely that remote_submodule_branch() would fail after successfully obtaining a remote ref name from get_default_remote_submodule(), it is still possible. To prevent a potential memory leak, add a call to free(remote_name) at the early exit point.
---
submodule--helper: fix leak when remote_submodule_branch() failed
In builtin/submodule--helper.c:update_submodule(), remote_name is allocated in get_default_remote_submodule() but may leak due to failure of remote_submodule_branch. Add free(remote_name) at the eraly exit point.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1987%2Fbrandb97%2Ffix-update-submodule-leak-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1987/brandb97/fix-update-submodule-leak-v1
Pull-Request: https://github.com/git/git/pull/1987
builtin/submodule--helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
builtin/submodule--helper.c +3 -1
@@ -2660,8 +2660,10 @@ static int update_submodule(struct update_data *update_data)if (code)return code; code =remote_submodule_branch (update_data->sm_path, &branch); -if (code) +if (code) { +free (remote_name);return code; + } remote_ref =xstrfmt ("refs/remotes/%s/%s" , remote_name, branch);free (remote_name);
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
Signature · 1 line
gitgitgadget