]> granicus.if.org Git - icu/commitdiff
ICU-13380 Fix memory leak in DateFormatSymbols when loading AmPmMarkers and AmPmMarke...
authorFelipe Balbontín <fabalbon@google.com>
Tue, 3 Oct 2017 01:25:20 +0000 (01:25 +0000)
committerFelipe Balbontín <fabalbon@google.com>
Tue, 3 Oct 2017 01:25:20 +0000 (01:25 +0000)
X-SVN-Rev: 40525

icu4c/source/i18n/dtfmtsym.cpp
icu4c/source/test/intltest/dtfmrgts.cpp
icu4c/source/test/intltest/dtfmrgts.h

index 6dd4380a4df2913ddd1cc1df14a0140812a5a256..455a8e1ee41fef101e698cb5104cc651cb4ed0a8 100644 (file)
@@ -1630,20 +1630,24 @@ struct CalendarDataSink : public ResourceSink {
                 UnicodeString *aliasArray;
                 Hashtable *aliasMap;
                 if ((aliasArray = (UnicodeString*)arrays.get(*alias)) != NULL) {
-                    // Clone the array
-                    int32_t aliasArraySize = arraySizes.geti(*alias);
-                    LocalArray<UnicodeString> aliasArrayCopy(new UnicodeString[aliasArraySize], errorCode);
-                    if (U_FAILURE(errorCode)) { return; }
-                    uprv_arrayCopy(aliasArray, aliasArrayCopy.getAlias(), aliasArraySize);
-                    // Put the array on the 'arrays' map
                     UnicodeString *path = (UnicodeString*)aliasPathPairs[i + 1];
-                    arrays.put(*path, aliasArrayCopy.orphan(), errorCode);
-                    arraySizes.puti(*path, aliasArraySize, errorCode);
+                    if (arrays.get(*path) == NULL) {
+                        // Clone the array
+                        int32_t aliasArraySize = arraySizes.geti(*alias);
+                        LocalArray<UnicodeString> aliasArrayCopy(new UnicodeString[aliasArraySize], errorCode);
+                        if (U_FAILURE(errorCode)) { return; }
+                        uprv_arrayCopy(aliasArray, aliasArrayCopy.getAlias(), aliasArraySize);
+                        // Put the array on the 'arrays' map
+                        arrays.put(*path, aliasArrayCopy.orphan(), errorCode);
+                        arraySizes.puti(*path, aliasArraySize, errorCode);
+                    }
                     if (U_FAILURE(errorCode)) { return; }
                     mod = true;
                 } else if ((aliasMap = (Hashtable*)maps.get(*alias)) != NULL) {
                     UnicodeString *path = (UnicodeString*)aliasPathPairs[i + 1];
-                    maps.put(*path, aliasMap, errorCode);
+                    if (maps.get(*path) == NULL) {
+                        maps.put(*path, aliasMap, errorCode);
+                    }
                     if (U_FAILURE(errorCode)) { return; }
                     mod = true;
                 }
index 2d5b465779cdbddd1c2344f68466f3deff19c003..260f8fa52363a9841326a4881b35eb84333334de 100644 (file)
@@ -47,7 +47,7 @@ DateFormatRegressionTest::runIndexedTest( int32_t index, UBool exec, const char*
         CASE(14,Test4104136)
         CASE(15,Test4104522)
         CASE(16,Test4106807)
-        CASE(17,Test4108407) 
+        CASE(17,Test4108407)
         CASE(18,Test4134203)
         CASE(19,Test4151631)
         CASE(20,Test4151706)
@@ -63,6 +63,7 @@ DateFormatRegressionTest::runIndexedTest( int32_t index, UBool exec, const char*
         CASE(30,TestT10619)
         CASE(31,TestT10855)
         CASE(32,TestT10906)
+        CASE(33,TestT13380)
         default: name = ""; break;
     }
 }
@@ -1724,6 +1725,20 @@ void DateFormatRegressionTest::TestT10906(void) {
       }
 }
 
+void DateFormatRegressionTest::TestT13380(void) {
+    UErrorCode errorCode = U_ZERO_ERROR;
+    LocalPointer<DateFormat> enFmt(DateFormat::createDateInstance(DateFormat::kShort, Locale("en")), errorCode);
+    if (U_FAILURE(errorCode)) {
+        errln("failure creating 'en' DateFormat");
+    }
+
+    errorCode = U_ZERO_ERROR;
+    LocalPointer<DateFormat> tgFmt(DateFormat::createDateInstance(DateFormat::kShort, Locale("tg")), errorCode);
+    if (U_FAILURE(errorCode)) {
+        errln("failure creating 'tg' DateFormat");
+    }
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */
 
 //eof
index 38794591aebe3bdb53413083f74c9d9b779fa53e..be8dd0f226115f63c5d00a7b4858b033cb2e9f12 100644 (file)
@@ -59,6 +59,7 @@ public:
     void TestT10619(void);
     void TestT10855(void);
     void TestT10906(void);
+    void TestT13380(void);
  };
 
 #endif /* #if !UCONFIG_NO_FORMATTING */