From: Michael Stapelberg Date: Mon, 7 Nov 2011 21:34:39 +0000 (+0000) Subject: ipc: fix memory leaks when clients disconnect X-Git-Tag: 4.1~28^2~4 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2a78a5f2b6c8c011dfcd0e794a57728d6ed0fb71;p=i3%2Fi3 ipc: fix memory leaks when clients disconnect --- diff --git a/src/ipc.c b/src/ipc.c index b94ef613..0a738427 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -99,9 +99,12 @@ void ipc_send_event(const char *event, uint32_t message_type, const char *payloa */ void ipc_shutdown() { ipc_client *current; - TAILQ_FOREACH(current, &all_clients, clients) { + while (!TAILQ_EMPTY(&all_clients)) { + current = TAILQ_FIRST(&all_clients); shutdown(current->fd, SHUT_RDWR); close(current->fd); + TAILQ_REMOVE(&all_clients, current, clients); + free(current); } } @@ -743,10 +746,12 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { /* We can call TAILQ_REMOVE because we break out of the * TAILQ_FOREACH afterwards */ TAILQ_REMOVE(&all_clients, current, clients); + free(current); break; } ev_io_stop(EV_A_ w); + free(w); DLOG("IPC: client disconnected\n"); return;