]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon
authorPaul Tarjan <github@paulisageek.com>
Wed, 15 Apr 2026 13:27:27 +0000 (13:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Apr 2026 15:44:32 +0000 (08:44 -0700)
The `state.cookies` hashmap is initialized during daemon startup but
never freed during cleanup in the `done:` label of
fsmonitor_run_daemon().  The cookie entries also have names allocated
via strbuf_detach() that must be freed individually.

Iterate the hashmap to free each cookie name, then call
hashmap_clear_and_free() to release the entries and table.

Signed-off-by: Paul Tarjan <github@paulisageek.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsmonitor--daemon.c

index bc4571938cc1dbff2bf118589cb841714ec41aec..d8d32b01ef28594aa61b3d059915a54c08ba5b5e 100644 (file)
@@ -1404,6 +1404,15 @@ static int fsmonitor_run_daemon(void)
 done:
        pthread_cond_destroy(&state.cookies_cond);
        pthread_mutex_destroy(&state.main_lock);
+       {
+               struct hashmap_iter iter;
+               struct fsmonitor_cookie_item *cookie;
+
+               hashmap_for_each_entry(&state.cookies, &iter, cookie, entry)
+                       free(cookie->name);
+               hashmap_clear_and_free(&state.cookies,
+                                      struct fsmonitor_cookie_item, entry);
+       }
        fsm_listen__dtor(&state);
        fsm_health__dtor(&state);