341N/A###############################################################################
1370N/A# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
341N/A#
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#
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# Software.
919N/A#
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/A#
341N/A
341N/A4614834: Xlib color functions are not MT-safe
341N/A
341N/AIn a multithreaded Xlib client:
341N/A
341N/A * concurrent access to XAllocNamedColor() make the client crash
341N/A * concurrent access to XLookupColor() make the client crash
341N/A
341N/AThe cause of the problem is that in multithread environment some data
341N/Ain XLookupColor() and XAllocNamedColor() can be accessed/modified at
341N/Asame time by multi threads. Adding some lock and unlock code to make
341N/Asure only one thread can access the data at one time fixed the
341N/Aproblem.
341N/A
1370N/Adiff --git a/src/GetColor.c b/src/GetColor.c
1370N/Aindex cd0eb9f..62b3bce 100644
1370N/A--- a/src/GetColor.c
1370N/A+++ b/src/GetColor.c
1064N/A@@ -55,12 +55,14 @@ XColor *exact_def) /* RETURN */
341N/A if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
341N/A const char *tmpName = colorname;
341N/A
341N/A+ LockDisplay(dpy);
341N/A switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
341N/A XcmsRGBFormat)) {
341N/A case XcmsSuccess:
341N/A case XcmsSuccessWithCompression:
341N/A _XcmsRGB_to_XColor(&cmsColor_exact, exact_def, 1);
341N/A memcpy((char *)hard_def, (char *)exact_def, sizeof(XColor));
341N/A+ UnlockDisplay(dpy);
341N/A ret = XAllocColor(dpy, cmap, hard_def);
341N/A exact_def->pixel = hard_def->pixel;
341N/A return(ret);
1064N/A@@ -73,6 +75,7 @@ XColor *exact_def) /* RETURN */
341N/A */
341N/A break;
341N/A }
341N/A+ UnlockDisplay(dpy);
341N/A }
688N/A #endif
341N/A
1370N/Adiff --git a/src/LookupCol.c b/src/LookupCol.c
1370N/Aindex f7f969f..718e043 100644
1370N/A--- a/src/LookupCol.c
1370N/A+++ b/src/LookupCol.c
1064N/A@@ -53,6 +53,7 @@ XLookupColor (
341N/A if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
341N/A const char *tmpName = spec;
341N/A
341N/A+ LockDisplay(dpy);
341N/A switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact,
341N/A XcmsRGBFormat)) {
341N/A case XcmsSuccess:
1064N/A@@ -60,6 +61,7 @@ XLookupColor (
341N/A _XcmsRGB_to_XColor(&cmsColor_exact, def, 1);
341N/A memcpy((char *)scr, (char *)def, sizeof(XColor));
341N/A _XUnresolveColor(ccc, scr);
341N/A+ UnlockDisplay(dpy);
341N/A return(1);
341N/A case XcmsFailure:
341N/A case _XCMS_NEWNAME:
1064N/A@@ -70,6 +72,7 @@ XLookupColor (
341N/A */
341N/A break;
341N/A }
341N/A+ UnlockDisplay(dpy);
341N/A }
688N/A #endif
341N/A