[RFC PATCH 1/6] leak fix: cache_put_path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux