From: Junio C Hamano <gitster@pobox.com>
To: "Lidong Yan via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Lidong Yan <502024330056@smail.nju.edu.cn>
Subject: Re: [PATCH v3] mailinfo: fix pointential memory leak if `decode_header` failed
Date: Mon, 12 May 2025 12:32:08 -0700 [thread overview]
Message-ID: <xmqqbjrxsk07.fsf@gitster.g> (raw)
In-Reply-To: <pull.1956.v3.git.git.1747066627330.gitgitgadget@gmail.com> (Lidong Yan via GitGitGadget's message of "Mon, 12 May 2025 16:17:07 +0000")
"Lidong Yan via GitGitGadget" <gitgitgadget@gmail.com> writes:
> -static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
> +static int decode_q_segment(struct strbuf *out, const struct strbuf *q_seg,
> + int rfc2047)
> {
> const char *in = q_seg->buf;
> int c;
> - struct strbuf *out = xmalloc(sizeof(struct strbuf));
> strbuf_init(out, q_seg->len);
This strbuf_init() is still here?
> +static int decode_b_segment(struct strbuf *out, const struct strbuf *b_seg)
> {
> /* Decode in..ep, possibly in-place to ot */
> int c, pos = 0, acc = 0;
> const char *in = b_seg->buf;
> - struct strbuf *out = xmalloc(sizeof(struct strbuf));
> strbuf_init(out, b_seg->len);
Ditto.
> @@ -475,7 +474,7 @@ static int convert_to_utf8(struct mailinfo *mi,
> static void decode_header(struct mailinfo *mi, struct strbuf *it)
> {
> char *in, *ep, *cp;
> - struct strbuf outbuf = STRBUF_INIT, *dec;
> + struct strbuf outbuf = STRBUF_INIT, dec = STRBUF_INIT;
Initializing this at the caller side is good.
> @@ -530,18 +529,20 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
> default:
> goto release_return;
> case 'b':
> - dec = decode_b_segment(&piecebuf);
> + if ((found_error = decode_b_segment(&dec, &piecebuf)))
> + goto release_return;
> break;
> case 'q':
> - dec = decode_q_segment(&piecebuf, 1);
> + if ((found_error = decode_q_segment(&dec, &piecebuf, 1)))
> + goto release_return;
> break;
> }
> - if (convert_to_utf8(mi, dec, charset_q.buf))
> + if (convert_to_utf8(mi, &dec, charset_q.buf)) {
> goto release_return;
> + }
Don't enclose a single statement block inside {braces}.
Thanks.
next prev parent reply other threads:[~2025-05-12 19:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-08 13:38 [PATCH] decode_header: fix pointential memory leak if decode_header failed Lidong Yan via GitGitGadget
2025-05-08 22:16 ` Junio C Hamano
2025-05-09 1:51 ` lidongyan
2025-05-11 16:14 ` [PATCH v2] mailinfo: fix pointential memory leak if `decode_header` failed Lidong Yan via GitGitGadget
2025-05-12 14:12 ` Junio C Hamano
2025-05-12 16:17 ` [PATCH v3] " Lidong Yan via GitGitGadget
2025-05-12 19:32 ` Junio C Hamano [this message]
2025-05-13 2:49 ` [PATCH v4] " Lidong Yan via GitGitGadget
2025-05-13 13:34 ` Junio C Hamano
2025-05-13 13:42 ` lidongyan
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=xmqqbjrxsk07.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=502024330056@smail.nju.edu.cn \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.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).