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

Re: [RFC memory leak?] Minor memory leak fix

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 11, 2014, 19:42 UTC
Message-ID
<xmqqmwgwpln5.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140311124009.GI14327@paksenarrion.iveqy.com>
Fredrik Gustafsson <iveqy@iveqy.com> writes:
Show 12 quoted lines
> On Tue, Mar 11, 2014 at 06:58:11PM +0700, Duy Nguyen wrote:
>> On Tue, Mar 11, 2014 at 5:45 PM, Fredrik Gustafsson <iveqy@iveqy.com> wrote:
>> > Strbuf needs to be released even if it's locally declared.
>> 
>> "path" is declared static. So yes it's a leak but the leak is minimum.
>> Your patch would make more sense if "static" is gone and it's leaked
>> after every write_archive_entry call.
>
> That's one of the reasons of the RFC. I know Junio thinks that minor
> things shouldn't be fixed by themselfes because it takes up review
> bandwidth, so it's better to fix them once you touch that part of the
> code anyway. (At least that's how I've understood him).

Yes, but I at the same time think this "static struct strbuf" is a clear statement by the original author that this is not a leak per-se. The trade-off, if I am reading the code right, is between keeping a piece of memory that is large enough to hold the longest pathname until exit() vs saving repeated allocations and frees for each of the thousands of paths in the resulting archive.

I tend to think the original strikes a better balance between the two.

Previous: Fredrik Gustafsson
Message 6 of 6 in “[RFC memory leak?] Minor memory leak fix”
  1. Fredrik GustafssonMar 11, 2014
  2. Duy NguyenMar 11, 2014
  3. [[RFC memory leak, v.2]] Minor memory leak fixFredrik Gustafsson, Mar 11, 2014
  4. René ScharfeMar 11, 2014
  5. Fredrik GustafssonMar 11, 2014
  6. Junio C HamanoMar 11, 2014

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.