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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 11, 2014 at 13:00 UTC 64a7e92f28e9bc053cf68d9b2e9ce4fb40e60e98
1 file changed +8 -10
builtin/receive-pack.c
+8 -10
@@ -910,7 +910,6 @@ static const char *pack_lockfile;
910 static const char *unpack(int err_fd, struct shallow_info *si)
911 {
912 struct pack_header hdr;
913 - struct argv_array av = ARGV_ARRAY_INIT;
913 const char *hdr_err;
914 int status;
915 char hdr_arg[38];
@@ -933,17 +932,17 @@ static const char *unpack(int err_fd, struct shallow_info *si)
932
933 if (si->nr_ours || si->nr_theirs) {
934 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);
937 }
938
939 memset(&child, 0, sizeof(child));
940 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);
942 if (quiet)
943 - argv_array_push(&av, "-q");
943 + argv_array_push(&child.args, "-q");
944 if (fsck_objects)
945 - argv_array_push(&av, "--strict");
946 - child.argv = av.argv;
945 + argv_array_push(&child.args, "--strict");
946 child.no_stdout = 1;
947 child.err = err_fd;
948 child.git_cmd = 1;
@@ -958,13 +957,12 @@ static const char *unpack(int err_fd, struct shallow_info *si)
957 if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
958 strcpy(keep_arg + s, "localhost");
959
961 - argv_array_pushl(&av, "index-pack",
960 + argv_array_pushl(&child.args, "index-pack",
961 "--stdin", hdr_arg, keep_arg, NULL);
962 if (fsck_objects)
964 - argv_array_push(&av, "--strict");
963 + argv_array_push(&child.args, "--strict");
964 if (fix_thin)
966 - argv_array_push(&av, "--fix-thin");
967 - child.argv = av.argv;
965 + argv_array_push(&child.args, "--fix-thin");
966 child.out = -1;
967 child.err = err_fd;
968 child.git_cmd = 1;