From 4e5886643f3161d16153a82cced6cc8fc1051da5 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Thu, 24 Apr 2014 18:48:06 +0000 Subject: [PATCH] ICU-10803 Fix race in LocaleUtility::getAvailableLocaleNames(). X-SVN-Rev: 35651 --- icu4c/source/common/locutil.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/icu4c/source/common/locutil.cpp b/icu4c/source/common/locutil.cpp index 17015cc479d..e5fe18c4c3c 100644 --- a/icu4c/source/common/locutil.cpp +++ b/icu4c/source/common/locutil.cpp @@ -240,10 +240,18 @@ LocaleUtility::getAvailableLocaleNames(const UnicodeString& bundleID) delete htp; return NULL; } - // See ticket #10803 umtx_lock(NULL); - cache->put(bundleID, (void*)htp, status); - umtx_unlock(NULL); + Hashtable *t = static_cast(cache->get(bundleID)); + if (t != NULL) { + // Another thread raced through this code, creating the cache entry first. + // Discard ours and return theirs. + umtx_unlock(NULL); + delete htp; + htp = t; + } else { + cache->put(bundleID, (void*)htp, status); + umtx_unlock(NULL); + } } } return htp; -- 2.40.0