]> granicus.if.org Git - icu/commitdiff
ICU-8718 Fix some memory leak issues in numbering systems
authorMichael Ow <mow@svn.icu-project.org>
Tue, 30 Aug 2011 03:22:38 +0000 (03:22 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Tue, 30 Aug 2011 03:22:38 +0000 (03:22 +0000)
X-SVN-Rev: 30592

icu4c/source/i18n/currpinf.cpp
icu4c/source/i18n/decimfmt.cpp
icu4c/source/i18n/numfmt.cpp
icu4c/source/i18n/numsys.cpp
icu4c/source/test/intltest/numfmtst.cpp

index 436e8929415800fd9918f88d18f7775250df8dd7..99f8cac9f7b4fe1c1706eccd4cabd38343c85a8c 100644 (file)
@@ -240,7 +240,7 @@ CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& st
         return;
     }
 
-       static NumberingSystem *ns = NumberingSystem::createInstance(loc,status);
+    NumberingSystem *ns = NumberingSystem::createInstance(loc,status);
     UErrorCode ec = U_ZERO_ERROR;
     UResourceBundle *rb = ures_open(NULL, loc.getName(), &ec);
     UResourceBundle *numElements = ures_getByKeyWithFallback(rb, gNumberElementsTag, NULL, &ec);
@@ -275,6 +275,7 @@ CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& st
 
     ures_close(numElements);
     ures_close(rb);
+    delete ns;
 
     if (U_FAILURE(ec)) {
         return;
index d8724fcae33a2b82f7a2237c13bd99e454dd0bb7..8cb72361266ef4805ffafe74d93b0caa69808dbd 100644 (file)
@@ -419,6 +419,8 @@ DecimalFormat::construct(UErrorCode&             status,
         ures_close(top);
     }
 
+    delete ns;
+
     if (U_FAILURE(status))
     {
         return;
@@ -501,6 +503,9 @@ DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) {
     }
 
     NumberingSystem *ns = NumberingSystem::createInstance(fSymbols->getLocale(),status);
+    if (U_FAILURE(status)) {
+        return;
+    }
 
     // Save the default currency patterns of this locale.
     // Here, chose onlyApplyPatternWithoutExpandAffix without
@@ -522,6 +527,7 @@ DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) {
     }
     ures_close(numElements);
     ures_close(resource);
+    delete ns;
 
     if (U_SUCCESS(error)) {
         applyPatternWithoutExpandAffix(UnicodeString(patResStr, patLen), false,
index 5354c4fd19f165e06af24ee484db3a20d3026614..d8540ae48b1b31aa1906cd6f509df154b94786e1 100644 (file)
@@ -1246,6 +1246,8 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
             patResStr = ures_getStringByKeyWithFallback(resource, gFormatKeys[style], &patLen, &status);
         }
 
+        ures_close(numElements);
+
         // Creates the specified decimal format style of the desired locale.
         pattern.setTo(TRUE, patResStr, patLen);
     }
index 6da31f421ecb9781a079c92649e4f836028eb0f7..7eae210326b893451982b32e326d1044c48e9e0f 100644 (file)
@@ -228,7 +228,7 @@ StringEnumeration* NumberingSystem::getAvailableNames(UErrorCode &status) {
     }
 
     if ( availableNames == NULL ) {
-        UVector *fNumsysNames = new UVector(status);
+        UVector *fNumsysNames = new UVector(uprv_deleteUObject, NULL, status);
         if (U_FAILURE(status)) {
             status = U_MEMORY_ALLOCATION_ERROR;
             return NULL;
index 1842bb63cdb7a3cf45cfc65f84ba3c6199e93eeb..398202a4c388c222d344232a127868ba2aef02aa 100644 (file)
@@ -6475,6 +6475,10 @@ void NumberFormatTest::TestAvailableNumberingSystems() {
         if ( uprv_strcmp(nsname,ns->getName()) ) {
             errln("FAIL: Numbering system name didn't match for name = %s\n",nsname);
         }
+
+        delete ns;
     }
+
+    delete availableNumberingSystems;
 }
 #endif /* #if !UCONFIG_NO_FORMATTING */