]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport: fix leaking arguments when fetching from bundle
authorPatrick Steinhardt <ps@pks.im>
Thu, 22 Aug 2024 09:18:08 +0000 (11:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2024 16:18:06 +0000 (09:18 -0700)
In `fetch_refs_from_bundle()` we assemble a vector of arguments to pass
to `unbundle()`, but never free it. And in theory we wouldn't have to
because `unbundle()` already knows to free the vector for us. But it
fails to do so when it exits early due to `verify_bundle()` failing.

The calling convention that the arguments are freed by the callee and
not the caller feels somewhat weird. Refactor the code such that it is
instead the responsibility of the caller to free the vector, adapting
the only two callsites where we pass extra arguments. This also fixes
the memory leak.

This memory leak gets hit in t5510, but fixing it isn't sufficient to
make the whole test suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/bundle.c
bundle.c
transport.c

index d5d41a8f6722cf95183a0c9ac5d746b58ac53a76..df97f3990194bbf49f5492a9740c676ebe833f75 100644 (file)
@@ -220,7 +220,9 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
                         &extra_index_pack_args, 0) ||
                list_bundle_refs(&header, argc, argv);
        bundle_header_release(&header);
+
 cleanup:
+       strvec_clear(&extra_index_pack_args);
        free(bundle_file);
        return ret;
 }
index ce164c37bc890c2dcbf13f01fa7f0b558164b2e4..0f6c7a71ef11816f2a1ebc3f992770c013439653 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -639,10 +639,8 @@ int unbundle(struct repository *r, struct bundle_header *header,
        if (flags & VERIFY_BUNDLE_FSCK)
                strvec_push(&ip.args, "--fsck-objects");
 
-       if (extra_index_pack_args) {
+       if (extra_index_pack_args)
                strvec_pushv(&ip.args, extra_index_pack_args->v);
-               strvec_clear(extra_index_pack_args);
-       }
 
        ip.in = bundle_fd;
        ip.no_stdout = 1;
index f0672fdc5058b61ab6c7440a85ed5446afd4b25a..da639d3bff0f996877cecbc1ef75924c06fd72d7 100644 (file)
@@ -189,6 +189,8 @@ static int fetch_refs_from_bundle(struct transport *transport,
                       &extra_index_pack_args,
                       fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
        transport->hash_algo = data->header.hash_algo;
+
+       strvec_clear(&extra_index_pack_args);
        return ret;
 }