Skip to content

Commit ac2e7d5

Browse files
pks-tgitster
authored andcommitted
upload-pack: fix leaking child process data on reachability checks
We spawn a git-rev-list(1) command to perform reachability checks in "upload-pack.c". We do not release memory associated with the process in error cases though, thus leaking memory. Fix these by calling `child_process_clear()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7eb6f02 commit ac2e7d5

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

t/t5516-fetch-push.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1919
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
2020

2121
TEST_CREATE_REPO_NO_TEMPLATE=1
22+
TEST_PASSES_SANITIZE_LEAK=true
2223
. ./test-lib.sh
2324

2425
D=$(pwd)

upload-pack.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,13 @@ static int get_reachable_list(struct upload_pack_data *data,
709709
struct object *o;
710710
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
711711
const unsigned hexsz = the_hash_algo->hexsz;
712+
int ret;
712713

713714
if (do_reachable_revlist(&cmd, &data->shallows, reachable,
714-
data->allow_uor) < 0)
715-
return -1;
715+
data->allow_uor) < 0) {
716+
ret = -1;
717+
goto out;
718+
}
716719

717720
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
718721
struct object_id oid;
@@ -736,10 +739,16 @@ static int get_reachable_list(struct upload_pack_data *data,
736739
}
737740
close(cmd.out);
738741

739-
if (finish_command(&cmd))
740-
return -1;
742+
if (finish_command(&cmd)) {
743+
ret = -1;
744+
goto out;
745+
}
741746

742-
return 0;
747+
ret = 0;
748+
749+
out:
750+
child_process_clear(&cmd);
751+
return ret;
743752
}
744753

745754
static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
@@ -749,7 +758,7 @@ static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
749758
int i;
750759

751760
if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
752-
return 1;
761+
goto error;
753762

754763
/*
755764
* The commits out of the rev-list are not ancestors of
@@ -775,6 +784,7 @@ static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
775784
error:
776785
if (cmd.out >= 0)
777786
close(cmd.out);
787+
child_process_clear(&cmd);
778788
return 1;
779789
}
780790

0 commit comments

Comments
 (0)