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

Re: [PATCH] repository: prevent memory leak when releasing ref stores

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 6, 2024, 15:44 UTC
Message-ID
<xmqqcymlzmec.fsf@gitster.g>
In-Reply-To
<ZrHAu0wfipR6CShS@tanuki>
Patrick Steinhardt <ps@pks.im> writes:
Show 9 quoted lines
>> Something along the following line (caution: totally untested) that
>> allows your two patches to become empty, and also allows a few
>> callers to lose their existing explicit free()s immediately after
>> they call _release(), perhaps?
>
> I don't really know whether it's worth the churn, but if somebody wants
> to pull through with this I'm game :) But: if we are going to do this,
> we should rename the function to be called `ref_store_free()` instead of
> `ref_store_release()` according to our recent coding style update :)
Yes, we had "what is release, clear, and free?" discussion recently.
Show 5 quoted lines
>> If this were to become a real patch, I think debug backend should
>> learn to use the same _downcast() to become more like the real ones
>> before it happens in a preliminary clean-up patch.
>
> That certainly wouldn't hurt, yeah.

I am not short of (other) things to do, and expect that I will not touching this for a while, but in case somebody finds #leftoverbits here, I'll leave a note here.

There are "hidden" freeing that we have to adjust, if we were to follow through this approach. For example, those free()'s added in the patch in the message that started the thread are introduing double free---after the strmap_for_each_entry() loop, a strmap_clear() callis done with free_values=1. If we freed inside ref_store_release(), we'd need to adjust the call to strmap_clear() to pass free_values=0 to compensate.

Previous: Patrick Steinhardt
Message 7 of 7 in “repository: prevent memory leak when releasing ref stores”
  1. repository: prevent memory leak when releasing ref storesSven Strickroth via GitGitGadget, Aug 5, 2024
  2. Sven StrickrothAug 5, 2024
  3. Junio C HamanoAug 5, 2024
  4. Junio C HamanoAug 5, 2024
  5. Junio C HamanoAug 5, 2024
  6. Patrick SteinhardtAug 6, 2024
  7. Junio C HamanoAug 6, 2024

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.