From 17c55792c6c20df0085c79fa82d03322aa04a377 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 9 Jan 2016 17:05:40 +0100 Subject: [PATCH] fix memory leak: use xcb_disconnect() instead of free() --- src/restore_layout.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/restore_layout.c b/src/restore_layout.c index af77b11d..4b9dc4ae 100644 --- a/src/restore_layout.c +++ b/src/restore_layout.c @@ -98,7 +98,11 @@ void restore_connect(void) { free(state); } - free(restore_conn); + /* xcb_disconnect leaks memory in libxcb versions earlier than 1.11, + * but it’s the right function to call. See + * http://cgit.freedesktop.org/xcb/libxcb/commit/src/xcb_conn.c?id=4dcbfd77b + */ + xcb_disconnect(restore_conn); free(xcb_watcher); free(xcb_check); free(xcb_prepare); @@ -106,8 +110,12 @@ void restore_connect(void) { int screen; restore_conn = xcb_connect(NULL, &screen); - if (restore_conn == NULL || xcb_connection_has_error(restore_conn)) + if (restore_conn == NULL || xcb_connection_has_error(restore_conn)) { + if (restore_conn != NULL) { + xcb_disconnect(restore_conn); + } errx(EXIT_FAILURE, "Cannot open display\n"); + } xcb_watcher = scalloc(1, sizeof(struct ev_io)); xcb_check = scalloc(1, sizeof(struct ev_check)); -- 2.39.5