Fix small leak in Collator
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Jan 2015 08:44:28 +0000 (08:44 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Jan 2015 08:44:28 +0000 (08:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140990

Reviewed by Andreas Kling.

* wtf/unicode/icu/CollatorICU.cpp:
(WTF::Collator::Collator): Use fastStrDup instead of strdup.
(WTF::Collator::~Collator): Use fastFree on the collator locale that we
are abandoning. The old code instead just called free on a null pointer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179245 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/unicode/icu/CollatorICU.cpp

index 423859683406d44caf7e0947fc559e7529b73765..c5ad4ad8fa69d1bbc8a64cf84754024523722249 100644 (file)
@@ -1,3 +1,15 @@
+2015-01-28  Darin Adler  <darin@apple.com>
+
+        Fix small leak in Collator
+        https://bugs.webkit.org/show_bug.cgi?id=140990
+
+        Reviewed by Andreas Kling.
+
+        * wtf/unicode/icu/CollatorICU.cpp:
+        (WTF::Collator::Collator): Use fastStrDup instead of strdup.
+        (WTF::Collator::~Collator): Use fastFree on the collator locale that we
+        are abandoning. The old code instead just called free on a null pointer.
+
 2015-01-27  Geoffrey Garen  <ggaren@apple.com>
 
         Removed WTF_MALLOC_VALIDATION
index 44f77f1a9782d2c5404d4f9374e6374fac5271e5..77b6a053b8a7989d5c0f2c75ff8f34a0fdfb3781 100644 (file)
@@ -141,24 +141,20 @@ Collator::Collator(const char* locale, bool shouldSortLowercaseFirst)
     ucol_setAttribute(m_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
     ASSERT(U_SUCCESS(status));
 
-    m_locale = locale ? strdup(locale) : nullptr;
+    m_locale = locale ? fastStrDup(locale) : nullptr;
     m_shouldSortLowercaseFirst = shouldSortLowercaseFirst;
 }
 
 Collator::~Collator()
 {
-    {
-        std::lock_guard<std::mutex> lock(cachedCollatorMutex());
-        if (cachedCollator)
-            ucol_close(cachedCollator);
-        cachedCollator = m_collator;
-        cachedCollatorLocale = m_locale;
-        cachedCollatorShouldSortLowercaseFirst = m_shouldSortLowercaseFirst;
-        m_collator = nullptr;
-        m_locale = nullptr;
+    std::lock_guard<std::mutex> lock(cachedCollatorMutex());
+    if (cachedCollator) {
+        ucol_close(cachedCollator);
+        fastFree(cachedCollatorLocale);
     }
-
-    free(m_locale);
+    cachedCollator = m_collator;
+    cachedCollatorLocale = m_locale;
+    cachedCollatorShouldSortLowercaseFirst = m_shouldSortLowercaseFirst;
 }
 
 static int32_t getIndexLatin1(UCharIterator* iterator, UCharIteratorOrigin origin)