mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-21419 Fix memory leak in AliasReplacer
This commit is contained in:
parent
d0096a84e7
commit
63cd3a7d40
3 changed files with 17 additions and 7 deletions
|
@ -1410,7 +1410,7 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
|
|||
.build(status);
|
||||
l.addLikelySubtags(status);
|
||||
const char* likelyRegion = l.getCountry();
|
||||
CharString* item = nullptr;
|
||||
LocalPointer<CharString> item;
|
||||
if (likelyRegion != nullptr && uprv_strlen(likelyRegion) > 0) {
|
||||
size_t len = uprv_strlen(likelyRegion);
|
||||
const char* foundInReplacement = uprv_strstr(replacement,
|
||||
|
@ -1422,20 +1422,22 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
|
|||
*(foundInReplacement-1) == ' ');
|
||||
U_ASSERT(foundInReplacement[len] == ' ' ||
|
||||
foundInReplacement[len] == '\0');
|
||||
item = new CharString(foundInReplacement, (int32_t)len, status);
|
||||
item.adoptInsteadAndCheckErrorCode(
|
||||
new CharString(foundInReplacement, (int32_t)len, status), status);
|
||||
}
|
||||
}
|
||||
if (item == nullptr) {
|
||||
item = new CharString(replacement,
|
||||
(int32_t)(firstSpace - replacement), status);
|
||||
if (item.isNull() && U_SUCCESS(status)) {
|
||||
item.adoptInsteadAndCheckErrorCode(
|
||||
new CharString(replacement,
|
||||
(int32_t)(firstSpace - replacement), status), status);
|
||||
}
|
||||
if (U_FAILURE(status)) { return false; }
|
||||
if (item == nullptr) {
|
||||
if (item.isNull()) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
replacedRegion = item->data();
|
||||
toBeFreed.addElement(item, status);
|
||||
toBeFreed.addElement(item.orphan(), status);
|
||||
}
|
||||
U_ASSERT(!same(region, replacedRegion));
|
||||
region = replacedRegion;
|
||||
|
|
|
@ -281,6 +281,7 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c
|
|||
TESTCASE_AUTO(TestSetUnicodeKeywordValueInLongLocale);
|
||||
TESTCASE_AUTO(TestSetUnicodeKeywordValueNullInLongLocale);
|
||||
TESTCASE_AUTO(TestCanonicalize);
|
||||
TESTCASE_AUTO(TestLeak21419);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
|
@ -6406,3 +6407,9 @@ void LocaleTest::TestSetUnicodeKeywordValueNullInLongLocale() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocaleTest::TestLeak21419() {
|
||||
IcuTestErrorCode status(*this, "TestLeak21419");
|
||||
Locale l = Locale("s-yU");
|
||||
l.canonicalize(status);
|
||||
}
|
||||
|
|
|
@ -153,6 +153,7 @@ public:
|
|||
void TestCapturingTagConvertingIterator();
|
||||
void TestSetUnicodeKeywordValueInLongLocale();
|
||||
void TestSetUnicodeKeywordValueNullInLongLocale();
|
||||
void TestLeak21419();
|
||||
|
||||
private:
|
||||
void _checklocs(const char* label,
|
||||
|
|
Loading…
Add table
Reference in a new issue