From 6cb5f9711e3fe5a4fec68764767c775ab20147b7 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Tue, 30 Jul 2019 06:40:18 +0100 Subject: [PATCH] core: deregister xerror handler in session_destroy xerror handler might be called during XCloseDisplay, at which point session_t is already destroyed, causing a segfault. Ping #209 Signed-off-by: Yuxuan Shui --- src/common.h | 2 ++ src/compton.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index f2ddd19a..87d14082 100644 --- a/src/common.h +++ b/src/common.h @@ -153,6 +153,8 @@ typedef struct session { // === Display related === /// Display in use. Display *dpy; + /// Previous handler of X errors + XErrorHandler previous_xerror_handler; /// Default screen. int scr; /// XCB connection. diff --git a/src/compton.c b/src/compton.c index e9dff9ab..38504a57 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1601,7 +1601,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy, const xcb_query_extension_reply_t *ext_info; - XSetErrorHandler(xerror); + ps->previous_xerror_handler = XSetErrorHandler(xerror); ps->scr = DefaultScreen(ps->dpy); @@ -2183,6 +2183,8 @@ static void session_destroy(session_t *ps) { xrc_report_xid(); #endif + XSetErrorHandler(ps->previous_xerror_handler); + // Stop libev event handlers ev_timer_stop(ps->loop, &ps->unredir_timer); ev_timer_stop(ps->loop, &ps->fade_timer);