ICU-8718 Fix some memory leak issues in numbering systems

X-SVN-Rev: 30592
This commit is contained in:
Michael Ow 2011-08-30 03:22:38 +00:00
parent d4bad5c896
commit 8ccd432155
5 changed files with 15 additions and 2 deletions

View 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;

View 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,

View 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);
}

View 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;

View 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 */