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

Re: [PATCH] Allocate msg only after fatal checks to avoid leaks

From
lidongyan <502024330056@smail.nju.edu.cn>
Date
Jun 14, 2025, 15:50 UTC
Message-ID
<089E9F89-5B21-4035-B500-8255622DA92A@smail.nju.edu.cn>
In-Reply-To
<xmqqcyb672mc.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 19 quoted lines
> 
> lidongyan <502024330056@smail.nju.edu.cn> writes:
> 
>> Alex via GitGitGadget <gitgitgadget@gmail.com> writes:
>>> 
>>> From: jinyaoguo <guo846@purdue.edu>
>>> 
>>> In parse_reuse_arg, we previously called xmalloc and strbuf_init
>>> before resolving the ref and reading the object, leading to a
>>> leaked msg on die() paths. This change moves the allocation of
>> 
>> A memory leak on the die() path shouldn't be considered a real leak,
>> right? Since the OS will clean up all memory once the process
>> terminates, explicitly freeing msg isn't necessary in this case.
> 
> It may not matter in practice, but I think the leak checking
> machinery like sanitizers would still complain, so I view efforts on
> plugging such leaks in the error code paths more about decluttering
> the leak checker output to help us spot the real leaks.

Makes sense. However, inserting a free-like statement in die() would be messier than using goto, since each die() has a unique message and we need to free stuff at each die().

Previous: Junio C HamanoNext: Jeff King
Message 5 of 7 in “Allocate msg only after fatal checks to avoid leaks”
  1. Allocate msg only after fatal checks to avoid leaksAlex via GitGitGadget, Jun 13, 2025
  2. Junio C HamanoJun 13, 2025
  3. lidongyanJun 14, 2025
  4. Junio C HamanoJun 14, 2025
  5. lidongyanJun 14, 2025
  6. Jeff KingJun 14, 2025
  7. Junio C HamanoJun 15, 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.