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