From 1b1b3456bc88a71b932b102d725c5ad29ed408d0 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 3 Oct 2018 14:20:33 +0200 Subject: [PATCH] Convert XGetSelectionOwner to XCB This also fixes a memory leak: buf was not freed if another composite manager was already running. Signed-off-by: Uli Schlachter --- src/compton.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compton.c b/src/compton.c index c6a8aed..9f131a3 100644 --- a/src/compton.c +++ b/src/compton.c @@ -3562,13 +3562,19 @@ register_cm(session_t *ps) { snprintf(buf, len, REGISTER_PROP "%d", ps->scr); buf[len - 1] = '\0'; atom = get_atom(ps, buf); + free(buf); - if (XGetSelectionOwner(ps->dpy, atom) != None) { + xcb_get_selection_owner_reply_t *reply = + xcb_get_selection_owner_reply(c, + xcb_get_selection_owner(c, atom), NULL); + + if (reply && reply->owner != XCB_NONE) { + free(reply); fprintf(stderr, "Another composite manager is already running\n"); return false; } + free(reply); xcb_set_selection_owner(c, ps->reg_win, atom, 0); - free(buf); } return true;