From 209c152e39ae22bf3842ff81f5b829c099d3aae7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 11 Apr 2010 19:52:34 +0300 Subject: [PATCH] Safety checks for X11 error handlers --- bin/override.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/bin/override.c b/bin/override.c index c6084d88e4..113a638445 100644 --- a/bin/override.c +++ b/bin/override.c @@ -192,6 +192,43 @@ int sigaction (int signum, const struct sigaction *act, struct sigaction *old) } +/*** Xlib ****/ +#ifdef HAVE_X11_XLIB_H +# include + +static pthread_mutex_t xlib_lock = PTHREAD_MUTEX_INITIALIZER; + +int (*XSetErrorHandler (int (*handler) (Display *, XErrorEvent *))) + (Display *, XErrorEvent *) +{ + if (override) + { + int (*ret) (Display *, XErrorEvent *); + + pthread_mutex_lock (&xlib_lock); + LOG("Error", "%p", handler); + ret = CALL(XSetErrorHandler, handler); + pthread_mutex_unlock (&xlib_lock); + return ret; + } + return CALL(XSetErrorHandler, handler); +} + +int (*XSetIOErrorHandler (int (*handler) (Display *))) (Display *) +{ + if (override) + { + int (*ret) (Display *); + + pthread_mutex_lock (&xlib_lock); + LOG("Error", "%p", handler); + ret = CALL(XSetIOErrorHandler, handler); + pthread_mutex_unlock (&xlib_lock); + return ret; + } + return CALL(XSetIOErrorHandler, handler); +} +#endif #else static void vlc_enable_override (void) { -- 2.39.2