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

Re: [PATCH 1/3] dir: fix leak of parent_hashmap and recursive_hashmap

From
Elijah Newren <newren@gmail.com>
Date
Aug 17, 2020, 16:57 UTC
Message-ID
<CABPp-BFBcMaPTvxE_PYqpHzo5zUG=Lv7Y+Oq2yCRYxRTgRQgLA@mail.gmail.com>
In-Reply-To
<20200816084328.GA1221900@coredump.intra.peff.net>
On Sun, Aug 16, 2020 at 1:43 AM Jeff King <peff@peff.net> wrote:
Show 15 quoted lines
>
> On Sun, Aug 16, 2020 at 06:59:09AM +0000, Elijah Newren via GitGitGadget wrote:
>
> > From: Elijah Newren <newren@gmail.com>
> >
> > Commit 96cc8ab531 ("sparse-checkout: use hashmaps for cone patterns",
> > 2019-11-21) added a parent_hashmap and recursive_hashmap to each struct
> > pattern_list and initialized these in add_patterns_from_buffer() but did
> > not make sure to add necessary code to clear_pattern_list() to free
> > these new structures.  Call hashmap_free_() on each to plug this memory
> > leak.
>
> Beat you to it. :)
>
> See: https://lore.kernel.org/git/20200814111049.GA4101811@coredump.intra.peff.net/

Doh! However, you do need to take care to free the hash table in addition to the hash entries, or you'll still have a leak (I actually made the same mistake)... I'll add those comments on your patch, though.

Previous: Jeff KingNext: Elijah Newren via GitGitGadget
Message 4 of 15 in “Clean up some memory leaks in and around dir.c”
  1. 0/3 Clean up some memory leaks in and around dir.cElijah Newren via GitGitGadget, Aug 16, 2020
  2. 1/3 dir: fix leak of parent_hashmap and recursive_hashmapElijah Newren via GitGitGadget, Aug 16, 2020
  3. Jeff KingAug 16, 2020
  4. Elijah NewrenAug 17, 2020
  5. 3/3 dir: fix problematic API to avoid memory leaksElijah Newren via GitGitGadget, Aug 16, 2020
  6. Jeff KingAug 16, 2020
  7. Elijah NewrenAug 17, 2020
  8. Jeff KingAug 17, 2020
  9. 2/3 dir: make clear_directory() free all relevant memoryElijah Newren via GitGitGadget, Aug 16, 2020
  10. Jeff KingAug 16, 2020
  11. Elijah NewrenAug 17, 2020
  12. 0/2 Clean up some memory leaks in and around dir.cElijah Newren via GitGitGadget, Aug 18, 2020
  13. 1/2 dir: make clear_directory() free all relevant memoryElijah Newren via GitGitGadget, Aug 18, 2020
  14. 2/2 dir: fix problematic API to avoid memory leaksElijah Newren via GitGitGadget, Aug 18, 2020
  15. Jeff KingAug 19, 2020

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.