Fix small leak in Collator
[WebKit-https.git] / Source / WTF / wtf / unicode / icu / CollatorICU.cpp
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)