Skip to content

Commit 64a7e92

Browse files
rscharfegitster
authored andcommitted
receive-pack: plug minor memory leak in unpack()
The argv_array used in unpack() is never freed. Instead of adding explicit calls to argv_array_clear() use the args member of struct child_process and let run_command() and friends clean up for us. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76f8611 commit 64a7e92

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

builtin/receive-pack.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,6 @@ static const char *pack_lockfile;
910910
static const char *unpack(int err_fd, struct shallow_info *si)
911911
{
912912
struct pack_header hdr;
913-
struct argv_array av = ARGV_ARRAY_INIT;
914913
const char *hdr_err;
915914
int status;
916915
char hdr_arg[38];
@@ -933,17 +932,17 @@ static const char *unpack(int err_fd, struct shallow_info *si)
933932

934933
if (si->nr_ours || si->nr_theirs) {
935934
alt_shallow_file = setup_temporary_shallow(si->shallow);
936-
argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL);
935+
argv_array_push(&child.args, "--shallow-file");
936+
argv_array_push(&child.args, alt_shallow_file);
937937
}
938938

939939
memset(&child, 0, sizeof(child));
940940
if (ntohl(hdr.hdr_entries) < unpack_limit) {
941-
argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL);
941+
argv_array_pushl(&child.args, "unpack-objects", hdr_arg, NULL);
942942
if (quiet)
943-
argv_array_push(&av, "-q");
943+
argv_array_push(&child.args, "-q");
944944
if (fsck_objects)
945-
argv_array_push(&av, "--strict");
946-
child.argv = av.argv;
945+
argv_array_push(&child.args, "--strict");
947946
child.no_stdout = 1;
948947
child.err = err_fd;
949948
child.git_cmd = 1;
@@ -958,13 +957,12 @@ static const char *unpack(int err_fd, struct shallow_info *si)
958957
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
959958
strcpy(keep_arg + s, "localhost");
960959

961-
argv_array_pushl(&av, "index-pack",
960+
argv_array_pushl(&child.args, "index-pack",
962961
"--stdin", hdr_arg, keep_arg, NULL);
963962
if (fsck_objects)
964-
argv_array_push(&av, "--strict");
963+
argv_array_push(&child.args, "--strict");
965964
if (fix_thin)
966-
argv_array_push(&av, "--fix-thin");
967-
child.argv = av.argv;
965+
argv_array_push(&child.args, "--fix-thin");
968966
child.out = -1;
969967
child.err = err_fd;
970968
child.git_cmd = 1;

0 commit comments

Comments
 (0)