git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4] mailinfo: fix pointential memory leak if `decode_header` failed

From
lidongyan <502024330056@smail.nju.edu.cn>
Date
May 13, 2025, 13:42 UTC
Message-ID
<9DE4050D-B036-4477-93B0-FF738A6F5C3C@smail.nju.edu.cn>
In-Reply-To
<xmqq4ixoiqhu.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 写道:
Show 18 quoted lines
> 
> "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);
>> + strbuf_grow(out, q_seg->len);
> 
> Call to grow(), while it does not hurt correctness, would not be
> necessary here, but let's take this code as-is.  As the result of Q
> encoding (and B encoding as well) always is longer than the decoded
> result, strbuf_grow(out, q_seg->len) would always be over-allocating,
> but it would not hurt too much.

Thanks for your advice. Though I think `strbuf_init(out, q_seg->len)` also call `strbuf_grow` to reserve `q_seg->len` size memory for `out`. `strbuf_grow` here prevent multiple realloc operations that might occur when calling `strbuf_addch`.

Previous: Junio C Hamano
Message 10 of 10 in “decode_header: fix pointential memory leak if decode_header failed”
  1. decode_header: fix pointential memory leak if decode_header failedLidong Yan via GitGitGadget, May 8, 2025
  2. Junio C HamanoMay 8, 2025
  3. lidongyanMay 9, 2025
  4. mailinfo: fix pointential memory leak if `decode_header` failedLidong Yan via GitGitGadget, May 11, 2025
  5. Junio C HamanoMay 12, 2025
  6. mailinfo: fix pointential memory leak if `decode_header` failedLidong Yan via GitGitGadget, May 12, 2025
  7. Junio C HamanoMay 12, 2025
  8. mailinfo: fix pointential memory leak if `decode_header` failedLidong Yan via GitGitGadget, May 13, 2025
  9. Junio C HamanoMay 13, 2025
  10. lidongyanMay 13, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.