ICU-10640 Fix memory leak in adoptNumberFormat code.

X-SVN-Rev: 35116
This commit is contained in:
Travis Keep 2014-02-10 22:52:01 +00:00
parent 059f862c4a
commit 8f7065db65
2 changed files with 8 additions and 5 deletions

View File

@ -579,6 +579,7 @@ void MeasureFormat::initMeasureFormat(
NumberFormat *nfToAdopt,
UErrorCode &status) {
static const char *listStyles[] = {"unit", "unit-short", "unit-narrow"};
LocalPointer<NumberFormat> nf(nfToAdopt);
if (U_FAILURE(status)) {
return;
}
@ -597,7 +598,7 @@ void MeasureFormat::initMeasureFormat(
return;
}
pluralRules->removeRef();
if (nfToAdopt == NULL) {
if (nf.getAlias() == NULL) {
SharedObject::copyPtr(
NumberFormat::createSharedInstance(
locale, UNUM_DECIMAL, status),
@ -607,7 +608,7 @@ void MeasureFormat::initMeasureFormat(
}
numberFormat->removeRef();
} else {
adoptNumberFormat(nfToAdopt, status);
adoptNumberFormat(nf.orphan(), status);
if (U_FAILURE(status)) {
return;
}
@ -623,6 +624,7 @@ void MeasureFormat::initMeasureFormat(
void MeasureFormat::adoptNumberFormat(
NumberFormat *nfToAdopt, UErrorCode &status) {
if (U_FAILURE(status)) {
delete nfToAdopt;
return;
}
SharedNumberFormat *shared = new SharedNumberFormat(nfToAdopt);

View File

@ -620,6 +620,7 @@ UnicodeString& RelativeDateTimeFormatter::combineDateAndTime(
void RelativeDateTimeFormatter::init(
const Locale &locale, NumberFormat *nfToAdopt, UErrorCode &status) {
LocalPointer<NumberFormat> nf(nfToAdopt);
if (!getFromCache(locale.getName(), cache, status)) {
return;
}
@ -631,7 +632,7 @@ void RelativeDateTimeFormatter::init(
return;
}
pluralRules->removeRef();
if (nfToAdopt == NULL) {
if (nf.getAlias() == NULL) {
SharedObject::copyPtr(
NumberFormat::createSharedInstance(
locale, UNUM_DECIMAL, status),
@ -641,12 +642,12 @@ void RelativeDateTimeFormatter::init(
}
numberFormat->removeRef();
} else {
SharedNumberFormat *shared = new SharedNumberFormat(nfToAdopt);
SharedNumberFormat *shared = new SharedNumberFormat(nf.getAlias());
if (shared == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
delete nfToAdopt;
return;
}
nf.orphan();
SharedObject::copyPtr(shared, numberFormat);
}
}