From: Michael Ow Date: Tue, 30 Aug 2011 03:22:38 +0000 (+0000) Subject: ICU-8718 Fix some memory leak issues in numbering systems X-Git-Tag: milestone-59-0-1~4559 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ccd4321558f6b0fcb849771d4b147f0a72cb285;p=icu ICU-8718 Fix some memory leak issues in numbering systems X-SVN-Rev: 30592 --- diff --git a/icu4c/source/i18n/currpinf.cpp b/icu4c/source/i18n/currpinf.cpp index 436e8929415..99f8cac9f7b 100644 --- a/icu4c/source/i18n/currpinf.cpp +++ b/icu4c/source/i18n/currpinf.cpp @@ -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; diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index d8724fcae33..8cb72361266 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -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, diff --git a/icu4c/source/i18n/numfmt.cpp b/icu4c/source/i18n/numfmt.cpp index 5354c4fd19f..d8540ae48b1 100644 --- a/icu4c/source/i18n/numfmt.cpp +++ b/icu4c/source/i18n/numfmt.cpp @@ -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); } diff --git a/icu4c/source/i18n/numsys.cpp b/icu4c/source/i18n/numsys.cpp index 6da31f421ec..7eae210326b 100644 --- a/icu4c/source/i18n/numsys.cpp +++ b/icu4c/source/i18n/numsys.cpp @@ -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; diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 1842bb63cdb..398202a4c38 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -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 */