[RFC PATCH 1/6] leak fix: cache_put_path
- From
Calvin Wan <calvinwan@google.com>
- Date
- Feb 13, 2023, 18:21 UTC
- Message-ID
- <20230213182134.2173280-2-calvinwan@google.com>
- In-Reply-To
- <20230213182134.2173280-1-calvinwan@google.com>
hashmap_put returns a pointer if the key was found and subsequently replaced. Free this pointer so it isn't leaked.
Signed-off-by: Calvin Wan <calvinwan@google.com> --- submodule-config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/submodule-config.c b/submodule-config.c index 4dc61b3a78..90cab34568 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -128,9 +128,11 @@ static void cache_put_path(struct submodule_cache *cache, unsigned int hash = hash_oid_string(&submodule->gitmodules_oid, submodule->path); struct submodule_entry *e = xmalloc(sizeof(*e)); + struct hashmap_entry *replaced; hashmap_entry_init(&e->ent, hash); e->config = submodule; - hashmap_put(&cache->for_path, &e->ent); + replaced = hashmap_put(&cache->for_path, &e->ent); + free(replaced); } static void cache_remove_path(struct submodule_cache *cache,
-- 2.39.1.581.gbfd45094c4-goog