From a4d504485139dc9bf4c846c26a38968a920dfcb1 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 2 Feb 2014 11:22:42 +0100 Subject: [PATCH 1/2] i3bar: fix resource leak: statusline_ctx needs to be freed first In practice this is rarely noticeable, unless you very often switch screen resolutions, I think. fixes #1172 --- i3bar/src/xcb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 82861039..3a9c061b 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -1395,8 +1395,8 @@ void realloc_sl_buffer(void) { mask |= XCB_GC_BACKGROUND; vals[0] = colors.bar_fg; - statusline_ctx = xcb_generate_id(xcb_connection); xcb_free_gc(xcb_connection, statusline_ctx); + statusline_ctx = xcb_generate_id(xcb_connection); xcb_void_cookie_t sl_ctx_cookie = xcb_create_gc_checked(xcb_connection, statusline_ctx, xcb_root, From a16dfdb15e2767d9753d45982b189de6edfdf70b Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 7 Mar 2014 23:56:25 -0500 Subject: [PATCH 2/2] Bugfix: ipc_receive_message reply leak The function ipc_recv_message in libi3 allocates memory to the location of the `message` reply in src/ipc_receive_message.c with malloc and must be freed. This memory leak was found using valgrind. --- src/ipc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ipc.c b/src/ipc.c index 4247ca5c..74edc741 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -833,14 +833,16 @@ handler_t handlers[8] = { static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { uint32_t message_type; uint32_t message_length; - uint8_t *message; + uint8_t *message = NULL; int ret = ipc_recv_message(w->fd, &message_type, &message_length, &message); /* EOF or other error */ if (ret < 0) { /* Was this a spurious read? See ev(3) */ - if (ret == -1 && errno == EAGAIN) + if (ret == -1 && errno == EAGAIN) { + FREE(message); return; + } /* If not, there was some kind of error. We don’t bother * and close the connection */ @@ -863,6 +865,7 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { ev_io_stop(EV_A_ w); free(w); + FREE(message); DLOG("IPC: client disconnected\n"); return; @@ -874,6 +877,8 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { handler_t h = handlers[message_type]; h(w->fd, message, 0, message_length, message_type); } + + FREE(message); } /*