]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/fetch-pack: cleanup before return error
authorLidong Yan <502024330056@smail.nju.edu.cn>
Wed, 4 Jun 2025 03:07:54 +0000 (03:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Jun 2025 15:52:25 +0000 (08:52 -0700)
In builtin/fetch-pack.c:cmd_fetch_pack(), if finish_connect() failed,
it returns error code without cleanup which cause memory leak. Add
cleanup label before frees in the end of cmd_fetch_pack(), and add
`goto cleanup` if finish_connect() failed.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch-pack.c

index d07eec9e5550ab919f938b9a24fda7b6a94d1dc6..d9e42bad58430dceae7076eeb1676be3851e5f1f 100644 (file)
@@ -274,8 +274,10 @@ int cmd_fetch_pack(int argc,
        }
        close(fd[0]);
        close(fd[1]);
-       if (finish_connect(conn))
-               return 1;
+       if (finish_connect(conn)) {
+               ret = 1;
+               goto cleanup;
+       }
 
        ret = !fetched_refs;
 
@@ -291,6 +293,7 @@ int cmd_fetch_pack(int argc,
                printf("%s %s\n",
                       oid_to_hex(&ref->old_oid), ref->name);
 
+cleanup:
        for (size_t i = 0; i < nr_sought; i++)
                free_one_ref(sought_to_free[i]);
        free(sought_to_free);