]> git.sur5r.net Git - i3/i3/commitdiff
fix memory leak: use xcb_disconnect() instead of free()
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 9 Jan 2016 16:05:40 +0000 (17:05 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 9 Jan 2016 16:06:58 +0000 (17:06 +0100)
src/restore_layout.c

index af77b11df7d97eeb08d040860ceb8369605754a9..4b9dc4ae560361412bc72abb1d3bfb1b7344a8cb 100644 (file)
@@ -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));