Skip to content

Commit 524c3e6

Browse files
ptarjangitster
authored andcommitted
fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon
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>
1 parent b8c5dd3 commit 524c3e6

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

builtin/fsmonitor--daemon.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,15 @@ static int fsmonitor_run_daemon(void)
14041404
done:
14051405
pthread_cond_destroy(&state.cookies_cond);
14061406
pthread_mutex_destroy(&state.main_lock);
1407+
{
1408+
struct hashmap_iter iter;
1409+
struct fsmonitor_cookie_item *cookie;
1410+
1411+
hashmap_for_each_entry(&state.cookies, &iter, cookie, entry)
1412+
free(cookie->name);
1413+
hashmap_clear_and_free(&state.cookies,
1414+
struct fsmonitor_cookie_item, entry);
1415+
}
14071416
fsm_listen__dtor(&state);
14081417
fsm_health__dtor(&state);
14091418

0 commit comments

Comments
 (0)