Re: [PATCH 13/13] sparse-checkout: free duplicate hashmap entries
On Fri, May 31, 2024 at 07:38:30AM -0400, Jeff King wrote:
Show 13 quoted lines
> @@ -533,8 +534,14 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
> e->pattern = xstrndup(oldpattern, newlen);
> hashmap_entry_init(&e->ent, fspathhash(e->pattern));
>
> - if (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL))
> + dup = hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL);
> + if (!dup)
> hashmap_add(&pl->parent_hashmap, &e->ent);
> + else {
> + free(e->pattern);
> + free(e);
> + e = dup;
> + }Nit: code style. The `if (!dup)` branch should also have curly braces.
Patrick