[PATCH v10 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon
- From
- Paul Tarjan via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 5, 2026, 01:16 UTC
- Message-ID
- <cb270120f0e27a34a58c856b7c80e78e2301c989.1772673378.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2147.v10.git.git.1772673378.gitgitgadget@gmail.com>
From: Paul Tarjan <github@paulisageek.com>
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> --- builtin/fsmonitor--daemon.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index bc4571938c..d8d32b01ef 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -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);
-- gitgitgadget