From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Calvin Wan <calvinwan@google.com>,
Josh Steadmon <steadmon@google.com>,
Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>, Toon claes <toon@iotcl.com>
Subject: [PATCH v2 03/22] send-pack: fix leaking common object IDs
Date: Thu, 5 Sep 2024 12:08:43 +0200 [thread overview]
Message-ID: <0d969962a39bb48bc1831129fb154997bd06093e.1725530720.git.ps@pks.im> (raw)
In-Reply-To: <cover.1725530720.git.ps@pks.im>
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 <ps@pks.im>
---
send-pack.c | 34 ++++++++++++++++++++++------------
t/t5549-fetch-push-http.sh | 1 +
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/send-pack.c b/send-pack.c
index fa2f5eec17b..b224ef9fc5e 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -508,7 +508,8 @@ int send_pack(struct send_pack_args *args,
if (!remote_refs) {
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
"Perhaps you should specify a branch.\n");
- return 0;
+ ret = 0;
+ goto out;
}
git_config_get_bool("push.negotiate", &push_negotiate);
@@ -615,12 +616,11 @@ int send_pack(struct send_pack_args *args,
* atomically, abort the whole operation.
*/
if (use_atomic) {
- strbuf_release(&req_buf);
- strbuf_release(&cap_buf);
reject_atomic_push(remote_refs, args->send_mirror);
error("atomic push failed for ref %s. status: %d\n",
ref->name, ref->status);
- return args->porcelain ? 0 : -1;
+ ret = args->porcelain ? 0 : -1;
+ goto out;
}
/* else fallthrough */
default:
@@ -682,8 +682,6 @@ int send_pack(struct send_pack_args *args,
write_or_die(out, req_buf.buf, req_buf.len);
packet_flush(out);
}
- strbuf_release(&req_buf);
- strbuf_release(&cap_buf);
if (use_sideband && cmds_sent) {
memset(&demux, 0, sizeof(demux));
@@ -721,7 +719,9 @@ int send_pack(struct send_pack_args *args,
finish_async(&demux);
}
fd[1] = -1;
- return -1;
+
+ ret = -1;
+ goto out;
}
if (!args->stateless_rpc)
/* Closed by pack_objects() via start_command() */
@@ -746,10 +746,12 @@ int send_pack(struct send_pack_args *args,
}
if (ret < 0)
- return ret;
+ goto out;
- if (args->porcelain)
- return 0;
+ if (args->porcelain) {
+ ret = 0;
+ goto out;
+ }
for (ref = remote_refs; ref; ref = ref->next) {
switch (ref->status) {
@@ -758,8 +760,16 @@ int send_pack(struct send_pack_args *args,
case REF_STATUS_OK:
break;
default:
- return -1;
+ ret = -1;
+ goto out;
}
}
- return 0;
+
+ ret = 0;
+
+out:
+ oid_array_clear(&commons);
+ strbuf_release(&req_buf);
+ strbuf_release(&cap_buf);
+ return ret;
}
diff --git a/t/t5549-fetch-push-http.sh b/t/t5549-fetch-push-http.sh
index 2cdebcb7356..6377fb6d993 100755
--- a/t/t5549-fetch-push-http.sh
+++ b/t/t5549-fetch-push-http.sh
@@ -5,6 +5,7 @@ test_description='fetch/push functionality using the HTTP protocol'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
--
2.46.0.519.g2e7b89e038.dirty
next prev parent reply other threads:[~2024-09-05 10:08 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 7:21 [PATCH 00/22] Memory leak fixes (pt.6) Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 01/22] t/test-lib: allow skipping leak checks for passing tests Patrick Steinhardt
2024-08-27 22:38 ` Junio C Hamano
2024-08-29 14:15 ` Toon claes
2024-08-30 9:00 ` Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 02/22] fetch-pack: fix memory leaks on fetch negotiation Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 03/22] send-pack: fix leaking common object IDs Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 04/22] builtin/push: fix leaking refspec query result Patrick Steinhardt
2024-08-30 21:59 ` Junio C Hamano
2024-09-02 9:27 ` Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 05/22] upload-pack: fix leaking child process data on reachability checks Patrick Steinhardt
2024-08-30 22:30 ` Junio C Hamano
2024-08-26 7:21 ` [PATCH 06/22] submodule: fix leaking fetch task data Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 07/22] builtin/submodule--helper: fix leaking refs on push-check Patrick Steinhardt
2024-08-26 7:21 ` [PATCH 08/22] remote: fix leaking tracking refs Patrick Steinhardt
2024-09-04 21:50 ` Junio C Hamano
2024-08-26 7:21 ` [PATCH 09/22] remote: fix leak in reachability check of a remote-tracking ref Patrick Steinhardt
2024-08-26 7:22 ` [PATCH 10/22] send-pack: fix leaking push cert nonce Patrick Steinhardt
2024-09-04 22:08 ` Junio C Hamano
2024-08-26 7:22 ` [PATCH 11/22] gpg-interface: fix misdesigned signing key interfaces Patrick Steinhardt
2024-09-04 22:09 ` Junio C Hamano
2024-08-26 7:22 ` [PATCH 12/22] object: clear grafts when clearing parsed object pool Patrick Steinhardt
2024-08-26 7:22 ` [PATCH 13/22] shallow: free grafts when unregistering them Patrick Steinhardt
2024-08-26 7:22 ` [PATCH 14/22] shallow: fix leaking members of `struct shallow_info` Patrick Steinhardt
2024-08-29 14:16 ` Toon claes
2024-08-29 16:07 ` Junio C Hamano
2024-08-30 9:00 ` Patrick Steinhardt
2024-08-26 7:22 ` [PATCH 15/22] negotiator/skipping: fix leaking commit entries Patrick Steinhardt
2024-08-28 20:29 ` Calvin Wan
2024-08-28 22:19 ` Josh Steadmon
2024-08-29 8:41 ` Patrick Steinhardt
2024-08-29 17:29 ` Calvin Wan
2024-08-26 7:22 ` [PATCH 16/22] builtin/repack: fix leaking line buffer when packing promisors Patrick Steinhardt
2024-09-04 22:27 ` Junio C Hamano
2024-08-26 7:22 ` [PATCH 17/22] builtin/pack-objects: plug leaking list of keep-packs Patrick Steinhardt
2024-08-26 7:22 ` [PATCH 18/22] builtin/grep: fix leaking object context Patrick Steinhardt
2024-09-04 22:36 ` Junio C Hamano
2024-08-26 7:22 ` [PATCH 19/22] builtin/fmt-merge-msg: fix leaking buffers Patrick Steinhardt
2024-08-26 7:22 ` [PATCH 20/22] match-trees: fix leaking prefixes in `shift_tree()` Patrick Steinhardt
2024-09-04 22:42 ` Junio C Hamano
2024-08-26 7:22 ` [PATCH 21/22] merge-ort: fix two leaks when handling directory rename modifications Patrick Steinhardt
2024-09-04 22:56 ` Junio C Hamano
2024-09-05 2:01 ` Elijah Newren
2024-08-26 7:22 ` [PATCH 22/22] builtin/repack: fix leaking keep-pack list Patrick Steinhardt
2024-09-04 23:01 ` [PATCH 00/22] Memory leak fixes (pt.6) Junio C Hamano
2024-09-05 10:08 ` [PATCH v2 " Patrick Steinhardt
2024-09-05 10:08 ` [PATCH v2 01/22] t/test-lib: allow skipping leak checks for passing tests Patrick Steinhardt
2024-09-05 10:08 ` [PATCH v2 02/22] fetch-pack: fix memory leaks on fetch negotiation Patrick Steinhardt
2024-09-05 10:08 ` Patrick Steinhardt [this message]
2024-09-05 10:08 ` [PATCH v2 04/22] builtin/push: fix leaking refspec query result Patrick Steinhardt
2024-09-05 10:08 ` [PATCH v2 05/22] upload-pack: fix leaking child process data on reachability checks Patrick Steinhardt
2024-09-05 10:08 ` [PATCH v2 06/22] submodule: fix leaking fetch task data Patrick Steinhardt
2024-09-05 10:08 ` [PATCH v2 07/22] builtin/submodule--helper: fix leaking refs on push-check Patrick Steinhardt
2024-09-05 10:08 ` [PATCH v2 08/22] remote: fix leaking tracking refs Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 09/22] remote: fix leak in reachability check of a remote-tracking ref Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 10/22] send-pack: fix leaking push cert nonce Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 11/22] gpg-interface: fix misdesigned signing key interfaces Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 12/22] object: clear grafts when clearing parsed object pool Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 13/22] shallow: free grafts when unregistering them Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 14/22] shallow: fix leaking members of `struct shallow_info` Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 15/22] negotiator/skipping: fix leaking commit entries Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 16/22] builtin/repack: fix leaking line buffer when packing promisors Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 17/22] builtin/pack-objects: plug leaking list of keep-packs Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 18/22] builtin/grep: fix leaking object context Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 19/22] builtin/fmt-merge-msg: fix leaking buffers Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 20/22] match-trees: fix leaking prefixes in `shift_tree()` Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 21/22] merge-ort: fix two leaks when handling directory rename modifications Patrick Steinhardt
2024-09-05 10:09 ` [PATCH v2 22/22] builtin/repack: fix leaking keep-pack list Patrick Steinhardt
2024-09-08 21:39 ` [PATCH v2 00/22] Memory leak fixes (pt.6) Junio C Hamano
2024-09-12 20:29 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0d969962a39bb48bc1831129fb154997bd06093e.1725530720.git.ps@pks.im \
--to=ps@pks.im \
--cc=calvinwan@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=steadmon@google.com \
--cc=toon@iotcl.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).