From 7c087d209a8564a0fc460edf3924d81100a5212d Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 22 Jan 2018 16:09:00 -0500 Subject: [PATCH] ecore-x: perform internal shutdown on io error if callback is set avoid crashing in callback when referencing dead display or handling events @fix --- src/lib/ecore_x/ecore_x.c | 47 ++++++++++++++++++------------- src/lib/ecore_x/ecore_x_error.c | 6 +++- src/lib/ecore_x/ecore_x_private.h | 1 + 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/lib/ecore_x/ecore_x.c b/src/lib/ecore_x/ecore_x.c index ff213a7784..3dab2b81cc 100644 --- a/src/lib/ecore_x/ecore_x.c +++ b/src/lib/ecore_x/ecore_x.c @@ -780,14 +780,11 @@ ecore_x_init_from_display(Ecore_X_Display *display) return --_ecore_x_init_count; } -static int -_ecore_x_shutdown(int close_display) +int +_ecore_x_shutdown(void) { - if (--_ecore_x_init_count != 0) - return _ecore_x_init_count; - if (!_ecore_x_disp) - return _ecore_x_init_count; + return 0; LOGFN(__FILE__, __LINE__, __FUNCTION__); @@ -854,19 +851,9 @@ _ecore_x_shutdown(int close_display) ECORE_X_EVENT_PRESENT_COMPLETE, ECORE_X_EVENT_PRESENT_IDLE); ecore_main_fd_handler_del(_ecore_x_fd_handler_handle); - if (close_display) - XCloseDisplay(_ecore_x_disp); - else - { - close(ConnectionNumber(_ecore_x_disp)); - // FIXME: may have to clean up x display internal here -// getting segv here? hmmm. odd. disable -// XFree(_ecore_x_disp); - } free(_ecore_x_event_handlers); _ecore_x_fd_handler_handle = NULL; - _ecore_x_disp = NULL; _ecore_x_event_handlers = NULL; _ecore_x_events_shutdown(); _ecore_x_input_shutdown(); @@ -874,6 +861,12 @@ _ecore_x_shutdown(int close_display) _ecore_x_dnd_shutdown(); ecore_x_netwm_shutdown(); + return 0; +} + +static void +_ecore_x_shutdown2(void) +{ ecore_event_shutdown(); ecore_shutdown(); @@ -881,8 +874,6 @@ _ecore_x_shutdown(int close_display) _ecore_xlib_log_dom = -1; eina_shutdown(); _ecore_xlib_sync = EINA_FALSE; - - return _ecore_x_init_count; } /** @@ -898,7 +889,14 @@ _ecore_x_shutdown(int close_display) EAPI int ecore_x_shutdown(void) { - return _ecore_x_shutdown(1); + if (--_ecore_x_init_count != 0) + return _ecore_x_init_count; + if (_ecore_x_shutdown()) return _ecore_x_init_count; + if (_ecore_x_disp) + XCloseDisplay(_ecore_x_disp); + _ecore_x_disp = NULL; + _ecore_x_shutdown2(); + return 0; } /** @@ -911,7 +909,16 @@ ecore_x_shutdown(void) EAPI int ecore_x_disconnect(void) { - return _ecore_x_shutdown(0); + if (--_ecore_x_init_count != 0) + return _ecore_x_init_count; + if (_ecore_x_shutdown()) return _ecore_x_init_count; + close(ConnectionNumber(_ecore_x_disp)); + // FIXME: may have to clean up x display internal here +// getting segv here? hmmm. odd. disable +// XFree(_ecore_x_disp); + _ecore_x_disp = NULL; + _ecore_x_shutdown2(); + return 0; } /** diff --git a/src/lib/ecore_x/ecore_x_error.c b/src/lib/ecore_x/ecore_x_error.c index ad3d32257a..9facf0733b 100644 --- a/src/lib/ecore_x/ecore_x_error.c +++ b/src/lib/ecore_x/ecore_x_error.c @@ -172,7 +172,11 @@ _ecore_x_io_error_handle(Display *d) if (d == _ecore_x_disp) { if (_io_error_func) - _io_error_func(_io_error_data); + { + _ecore_x_disp = NULL; + _ecore_x_shutdown(); + _io_error_func(_io_error_data); + } else exit(-1); } diff --git a/src/lib/ecore_x/ecore_x_private.h b/src/lib/ecore_x/ecore_x_private.h index 07c09fb16f..2254f150dc 100644 --- a/src/lib/ecore_x/ecore_x_private.h +++ b/src/lib/ecore_x/ecore_x_private.h @@ -395,6 +395,7 @@ Ecore_Event_Mouse_Button *_ecore_mouse_button(int event, void _ecore_x_modifiers_get(void); KeySym _ecore_x_XKeycodeToKeysym(Display *display, KeyCode keycode, int index); +int _ecore_x_shutdown(void); //#define LOGFNS 1 #ifdef LOGFNS