]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/submodule--helper: fix leak when remote_submodule_branch() failed
authorLidong Yan <502024330056@smail.nju.edu.cn>
Sun, 8 Jun 2025 03:56:59 +0000 (03:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Jun 2025 15:49:48 +0000 (08:49 -0700)
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.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c

index c1a8029714bfe9415445edde4831f693211f4ff9..c5f2863b55d80506a6d8717a768ba1e6e9de6b9b 100644 (file)
@@ -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);