Skip to content

Commit e03004f

Browse files
pks-tgitster
authored andcommitted
send-pack: fix leaking common object IDs
We're leaking the array of common object IDs in `send_pack()`. Fix this by creating a common exit path where we free the leaking data. While at it, unify some other cleanups now that we have a central place to put them. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6349491 commit e03004f

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

send-pack.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ int send_pack(struct send_pack_args *args,
508508
if (!remote_refs) {
509509
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
510510
"Perhaps you should specify a branch.\n");
511-
return 0;
511+
ret = 0;
512+
goto out;
512513
}
513514

514515
git_config_get_bool("push.negotiate", &push_negotiate);
@@ -615,12 +616,11 @@ int send_pack(struct send_pack_args *args,
615616
* atomically, abort the whole operation.
616617
*/
617618
if (use_atomic) {
618-
strbuf_release(&req_buf);
619-
strbuf_release(&cap_buf);
620619
reject_atomic_push(remote_refs, args->send_mirror);
621620
error("atomic push failed for ref %s. status: %d\n",
622621
ref->name, ref->status);
623-
return args->porcelain ? 0 : -1;
622+
ret = args->porcelain ? 0 : -1;
623+
goto out;
624624
}
625625
/* else fallthrough */
626626
default:
@@ -682,8 +682,6 @@ int send_pack(struct send_pack_args *args,
682682
write_or_die(out, req_buf.buf, req_buf.len);
683683
packet_flush(out);
684684
}
685-
strbuf_release(&req_buf);
686-
strbuf_release(&cap_buf);
687685

688686
if (use_sideband && cmds_sent) {
689687
memset(&demux, 0, sizeof(demux));
@@ -721,7 +719,9 @@ int send_pack(struct send_pack_args *args,
721719
finish_async(&demux);
722720
}
723721
fd[1] = -1;
724-
return -1;
722+
723+
ret = -1;
724+
goto out;
725725
}
726726
if (!args->stateless_rpc)
727727
/* Closed by pack_objects() via start_command() */
@@ -746,10 +746,12 @@ int send_pack(struct send_pack_args *args,
746746
}
747747

748748
if (ret < 0)
749-
return ret;
749+
goto out;
750750

751-
if (args->porcelain)
752-
return 0;
751+
if (args->porcelain) {
752+
ret = 0;
753+
goto out;
754+
}
753755

754756
for (ref = remote_refs; ref; ref = ref->next) {
755757
switch (ref->status) {
@@ -758,8 +760,16 @@ int send_pack(struct send_pack_args *args,
758760
case REF_STATUS_OK:
759761
break;
760762
default:
761-
return -1;
763+
ret = -1;
764+
goto out;
762765
}
763766
}
764-
return 0;
767+
768+
ret = 0;
769+
770+
out:
771+
oid_array_clear(&commons);
772+
strbuf_release(&req_buf);
773+
strbuf_release(&cap_buf);
774+
return ret;
765775
}

t/t5549-fetch-push-http.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='fetch/push functionality using the HTTP protocol'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910
. "$TEST_DIRECTORY"/lib-httpd.sh
1011
start_httpd

0 commit comments

Comments
 (0)