.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,
*(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;
TESTCASE_AUTO(TestSetUnicodeKeywordValueInLongLocale);
TESTCASE_AUTO(TestSetUnicodeKeywordValueNullInLongLocale);
TESTCASE_AUTO(TestCanonicalize);
+ TESTCASE_AUTO(TestLeak21419);
TESTCASE_AUTO_END;
}
}
}
}
+
+void LocaleTest::TestLeak21419() {
+ IcuTestErrorCode status(*this, "TestLeak21419");
+ Locale l = Locale("s-yU");
+ l.canonicalize(status);
+}