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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7eb6f02c55
commit
ac2e7d545e
@ -19,6 +19,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|||||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||||
|
|
||||||
TEST_CREATE_REPO_NO_TEMPLATE=1
|
TEST_CREATE_REPO_NO_TEMPLATE=1
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
D=$(pwd)
|
D=$(pwd)
|
||||||
|
@ -709,10 +709,13 @@ static int get_reachable_list(struct upload_pack_data *data,
|
|||||||
struct object *o;
|
struct object *o;
|
||||||
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
|
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
|
||||||
const unsigned hexsz = the_hash_algo->hexsz;
|
const unsigned hexsz = the_hash_algo->hexsz;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (do_reachable_revlist(&cmd, &data->shallows, reachable,
|
if (do_reachable_revlist(&cmd, &data->shallows, reachable,
|
||||||
data->allow_uor) < 0)
|
data->allow_uor) < 0) {
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
|
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
@ -736,10 +739,16 @@ static int get_reachable_list(struct upload_pack_data *data,
|
|||||||
}
|
}
|
||||||
close(cmd.out);
|
close(cmd.out);
|
||||||
|
|
||||||
if (finish_command(&cmd))
|
if (finish_command(&cmd)) {
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
ret = 0;
|
||||||
|
|
||||||
|
out:
|
||||||
|
child_process_clear(&cmd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
|
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)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
|
if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
|
||||||
return 1;
|
goto error;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The commits out of the rev-list are not ancestors of
|
* 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)
|
|||||||
error:
|
error:
|
||||||
if (cmd.out >= 0)
|
if (cmd.out >= 0)
|
||||||
close(cmd.out);
|
close(cmd.out);
|
||||||
|
child_process_clear(&cmd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user