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 <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-07-30 06:40:18 +01:00
parent d7415fcf2e
commit 6cb5f9711e
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 5 additions and 1 deletions

View File

@ -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.

View File

@ -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);