On Mon, Aug 17, 2020 at 9:55 AM Elijah Newren <newren@xxxxxxxxx> wrote: > > Hi, > > On Fri, Aug 14, 2020 at 5:23 AM Jeff King <peff@xxxxxxxx> wrote: > > > > Commit 96cc8ab531 (sparse-checkout: use hashmaps for cone patterns, > > 2019-11-21) added some auxiliary hashmaps to the pattern_list struct, > > but they're leaked when clear_pattern_list() is called. > > > > Signed-off-by: Jeff King <peff@xxxxxxxx> > > --- > > I have no idea how often this leak triggers in practice. I just noticed > > it while poking at LSan output (which we remain depressingly far > > from getting a clean run on). > > > > dir.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/dir.c b/dir.c > > index fe64be30ed..9411b94e9b 100644 > > --- a/dir.c > > +++ b/dir.c > > @@ -916,6 +916,8 @@ void clear_pattern_list(struct pattern_list *pl) > > free(pl->patterns[i]); > > free(pl->patterns); > > free(pl->filebuf); > > + hashmap_free_entries(&pl->recursive_hashmap, struct pattern_entry, ent); > > + hashmap_free_entries(&pl->parent_hashmap, struct pattern_entry, ent); > > This clears up the hash entries, but continues to leak the hash table. > Since you submitted first, can you fix this to use hashmap_free_() > instead, as per > https://lore.kernel.org/git/932741d7598ca2934dbca40f715ba2d3819fcc51.1597561152.git.gitgitgadget@xxxxxxxxx/? > Then I'll rebase my series on yours and drop my first patch (since > it'll then be identical). Nevermind, I got confused once again by the name. hashmap_free_entries() doesn't mean just free the entries, it means free what hashmap_free() would plus all the entries, i.e. do what hashmap_free() *should* *have* *been* defined to do. Such a confusing API. And hashmap_free() really perplexes me -- it seems like a function that can't possibly be useful; it's sole purpose seems to be a trap for the unwary.