Skip to content

Commit 7720460

Browse files
pks-tgitster
authored andcommitted
transport: fix leaking arguments when fetching from bundle
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c92abe7 commit 7720460

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

builtin/bundle.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
220220
&extra_index_pack_args, 0) ||
221221
list_bundle_refs(&header, argc, argv);
222222
bundle_header_release(&header);
223+
223224
cleanup:
225+
strvec_clear(&extra_index_pack_args);
224226
free(bundle_file);
225227
return ret;
226228
}

bundle.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,8 @@ int unbundle(struct repository *r, struct bundle_header *header,
639639
if (flags & VERIFY_BUNDLE_FSCK)
640640
strvec_push(&ip.args, "--fsck-objects");
641641

642-
if (extra_index_pack_args) {
642+
if (extra_index_pack_args)
643643
strvec_pushv(&ip.args, extra_index_pack_args->v);
644-
strvec_clear(extra_index_pack_args);
645-
}
646644

647645
ip.in = bundle_fd;
648646
ip.no_stdout = 1;

transport.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ static int fetch_refs_from_bundle(struct transport *transport,
189189
&extra_index_pack_args,
190190
fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
191191
transport->hash_algo = data->header.hash_algo;
192+
193+
strvec_clear(&extra_index_pack_args);
192194
return ret;
193195
}
194196

0 commit comments

Comments
 (0)