From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH] apply: plug strbuf leak
Date: Wed, 20 May 2026 15:28:53 +0900 [thread overview]
Message-ID: <xmqq33zm4msa.fsf@gitster.g> (raw)
Depending on how read_patch_file() fails, it may already have read
many bytes into the supplied strbuf. Either the caller or the callee
should release the strbuf.
Here we choose to make the sole caller of the function responsible
for releasing it, as it makes the error handling slightly simpler.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
apply.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/apply.c b/apply.c
index 4aa1694cfa..0167902325 100644
--- a/apply.c
+++ b/apply.c
@@ -4881,8 +4881,10 @@ static int apply_patch(struct apply_state *state,
state->patch_input_file = filename;
state->linenr = 1;
- if (read_patch_file(&buf, fd) < 0)
+ if (read_patch_file(&buf, fd) < 0) {
+ strbuf_release(&buf);
return -128;
+ }
offset = 0;
while (offset < buf.len) {
struct patch *patch;
--
2.54.0-398-ga4b2d32071
next reply other threads:[~2026-05-20 6:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 6:28 Junio C Hamano [this message]
2026-05-20 6:48 ` [PATCH] apply: plug strbuf leak 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=xmqq33zm4msa.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/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