X locking

Antti P Miettinen ananaza at iki.fi
Sun May 22 13:46:38 CDT 2005


The following would catch programs calling XInitThreads() too late. If
the lock remains uninitialized we get random memory references. Null
pointer ref should segfault reliably.

--- xorg-6.8.2/build-tree/xc/lib/X11/Xlibint.h~	2005-02-17 02:34:25.000000000 +0200
+++ xorg-6.8.2/build-tree/xc/lib/X11/Xlibint.h	2005-05-22 20:54:24.226001344 +0300
@@ -308,7 +308,13 @@
 #define _XLockMutex(lock)		if (_XLockMutex_fn) (*_XLockMutex_fn)(lock)
 #define _XUnlockMutex(lock)	if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock)
 #endif
-#define _XCreateMutex(lock)	if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock);
+#define _XCreateMutex(lock)			\
+do {						\
+    if (_XCreateMutex_fn)			\
+        (*_XCreateMutex_fn)(lock);		\
+    else					\
+	memset(lock, 0, sizeof(*lock));		\
+} while (0)
 #define _XFreeMutex(lock)	if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock);
 
 #else /* XTHREADS */




More information about the ubuntu-devel mailing list