4010755.patch revision 1370
98N/A###############################################################################
98N/A# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
98N/A#
98N/A# Permission is hereby granted, free of charge, to any person obtaining a
98N/A# copy of this software and associated documentation files (the "Software"),
98N/A# to deal in the Software without restriction, including without limitation
98N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
98N/A# and/or sell copies of the Software, and to permit persons to whom the
98N/A# Software is furnished to do so, subject to the following conditions:
98N/A#
98N/A# The above copyright notice and this permission notice (including the next
98N/A# paragraph) shall be included in all copies or substantial portions of the
98N/A# Software.
98N/A#
98N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
98N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
98N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
98N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
98N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
98N/A# DEALINGS IN THE SOFTWARE.
98N/A#
98N/A
98N/A4010755: SEGV in XFindContext if XInitThreads has been enabled
98N/A
98N/AXFindContext in Xlib was calling _XLockMutex with an uninitialized
98N/Amutex lock structure. The new version of XInitThreads activates the
98N/Alocking functions at any time, even after displays have been created.
98N/A
98N/AIn this new case, the context structure was created prior to
98N/AXInitThreads being invoked. As a result, the display contained an
98N/Aopaque pointer to this context structure, which still contained an
98N/Auninitialized lock structure.
98N/A
98N/AThe solution was to explicitly set the lock structure pointer to NULL
98N/A(as a flag) when creating the context, then check for NULL when
98N/Alocking. If NULL is found and threads are now enabled, then the
98N/Astructure gets reinitialized to the correct mutex lock structure
98N/Ain the lock call.
98N/A
98N/AAnother area besides the functions in Context.c are the functions in
98N/AXrm.c. A similar fix was added to them as well.
98N/A
98N/A
98N/Adiff --git a/src/Context.c b/src/Context.c
98N/Aindex 8a07871..dd4df6b 100644
98N/A--- a/src/Context.c
98N/A+++ b/src/Context.c
98N/A@@ -190,6 +190,9 @@ int XSaveContext(
98N/A return XCNOMEM;
98N/A }
98N/A db->numentries = 0;
98N/A+#ifdef SUNSOFT
98N/A+ db->linfo.lock = (xmutex_t) NULL;
98N/A+#endif
98N/A _XCreateMutex(&db->linfo);
98N/A #ifdef MOTIFBC
98N/A if (!display) *pdb = db; else
98N/Adiff --git a/src/Xrm.c b/src/Xrm.c
98N/Aindex 36b71d6..b3283e6 100644
98N/A--- a/src/Xrm.c
98N/A+++ b/src/Xrm.c
98N/A@@ -497,6 +497,9 @@ static XrmDatabase NewDatabase(void)
98N/A
98N/A db = Xmalloc(sizeof(XrmHashBucketRec));
98N/A if (db) {
98N/A+#ifdef SUNSOFT
98N/A+ db->linfo.lock = (xmutex_t) NULL;
98N/A+#endif
98N/A _XCreateMutex(&db->linfo);
98N/A db->table = (NTable)NULL;
98N/A db->mbstate = (XPointer)NULL;
98N/Adiff --git a/src/locking.c b/src/locking.c
98N/Aindex e4e0444..eb875e3 100644
98N/A--- a/src/locking.c
98N/A+++ b/src/locking.c
98N/A@@ -104,6 +104,16 @@ static void _XLockMutex(
98N/A XTHREADS_FILE_LINE_ARGS
98N/A )
98N/A {
98N/A+#ifdef SUNSOFT
98N/A+ /* Make sure any locks in structures that were created before calling
98N/A+ * XInitThreads are initialized before locking, now that we allow calls
98N/A+ * to XInitThreads after other Xlib calls (Sun bugs 1234757 & 4010755)
98N/A+ */
98N/A+ if (lip->lock == NULL) {
98N/A+ static void _XCreateMutex(LockInfoPtr lip); /* Forward declaration */
98N/A+ _XCreateMutex(lip);
98N/A+ }
98N/A+#endif /* SUNSOFT */
98N/A xmutex_lock(lip->lock);
98N/A }
98N/A
98N/A