From fcc5ce516b6bf7e2ff63052e10018f8fef47f838 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 30 Mar 2009 08:27:53 +0200 Subject: [PATCH] =?UTF-8?q?Bugfix:=20Don=E2=80=99t=20free=20xinerama-reply?= =?UTF-8?q?=20if=20it=20is=20NULL,=20implement=20FREE()-macro=20(Thanks=20?= =?UTF-8?q?Igor)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/util.h | 7 +++++++ src/xinerama.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/util.h b/include/util.h index a156f0a3..4100089b 100644 --- a/include/util.h +++ b/include/util.h @@ -24,6 +24,13 @@ #define FOR_TABLE(workspace) \ for (int cols = 0; cols < workspace->cols; cols++) \ for (int rows = 0; rows < workspace->rows; rows++) +#define FREE(pointer) do { \ + if (pointer == NULL) { \ + free(pointer); \ + pointer = NULL; \ + } \ +} \ +while (0) /* ##__VA_ARGS__ means: leave out __VA_ARGS__ completely if it is empty, that is, delete the preceding comma */ diff --git a/src/xinerama.c b/src/xinerama.c index 8d00eb4c..ac820bd8 100644 --- a/src/xinerama.c +++ b/src/xinerama.c @@ -206,14 +206,14 @@ void initialize_xinerama(xcb_connection_t *conn) { xcb_xinerama_is_active_reply_t *reply; reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL); - if (!reply->state) { + if (reply == NULL || !reply->state) { LOG("Xinerama is not active (in your X-Server), disabling.\n"); - free(reply); + FREE(reply); disable_xinerama(conn); return; } - free(reply); + FREE(reply); query_screens(conn, virtual_screens);