ICU-6911 Fix some memory leaks in cintltst and add value deleter in selfmt.

X-SVN-Rev: 27678
This commit is contained in:
Michael Ow 2010-02-25 19:19:53 +00:00
parent d8aaf83b90
commit 3bb1465e8d
4 changed files with 32 additions and 1 deletions

View file

@ -87,6 +87,7 @@ SelectFormat::applyPattern(const UnicodeString& newPattern, UErrorCode& status)
if (U_FAILURE(status)) {
return;
}
parsedValuesHash->setValueDeleter(uhash_deleteUnicodeString);
//Process the state machine
State state = startState;

View file

@ -681,6 +681,8 @@ static void TestMsgFormatSelect(void)
if(U_FAILURE(status)){
log_data_err("ERROR: failure in message format on Select test#1 : %s \n", myErrorName(status));
}
free(str);
free(str1);
/*Test a nested pattern*/
str=(UChar*)malloc(sizeof(UChar) * 25);
@ -709,7 +711,8 @@ static void TestMsgFormatSelect(void)
if(U_FAILURE(status)){
log_data_err("ERROR: failure in message format on Select test#2 : %s \n", myErrorName(status));
}
free(str);
free(str1);
}
/* test message format with a choice option */

View file

@ -768,6 +768,7 @@ free(result);
} else {
log_verbose("unum_parseDouble with empty groupingSep: no hang, OK\n");
}
unum_close(dec_en);
}
/*closing the NumberFormat() using unum_close(UNumberFormat*)")*/

View file

@ -106,6 +106,7 @@ static void test_assert_utext(const char *expected, UText *actual, const char *f
}
log_err("\"\n");
}
utext_close(&expectedText);
}
#define TEST_ASSERT_UTEXT(expected, actual) test_assert_utext(expected, actual, __FILE__, __LINE__)
@ -1862,6 +1863,7 @@ static void TestUTextAPI(void) {
UChar text2[80];
UText *fields[10];
int32_t numFields;
int32_t i;
u_uastrncpy(textToSplit, "first : second: third", sizeof(textToSplit)/2);
u_uastrncpy(text2, "No match here.", sizeof(text2)/2);
@ -1889,6 +1891,9 @@ static void TestUTextAPI(void) {
TEST_ASSERT_UTEXT(" third", fields[2]);
TEST_ASSERT(fields[3] == NULL);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
}
uregex_close(re);
@ -1915,6 +1920,9 @@ static void TestUTextAPI(void) {
TEST_ASSERT_UTEXT(" second: third", fields[1]);
TEST_ASSERT(fields[2] == &patternText);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
}
uregex_close(re);
@ -1926,6 +1934,7 @@ static void TestUTextAPI(void) {
UChar textToSplit[80];
UText *fields[10];
int32_t numFields;
int32_t i;
u_uastrncpy(textToSplit, "first <tag-a> second<tag-b> third", sizeof(textToSplit)/2);
@ -1951,6 +1960,9 @@ static void TestUTextAPI(void) {
TEST_ASSERT_UTEXT(" third", fields[4]);
TEST_ASSERT(fields[5] == NULL);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
}
/* Split with too few output strings available (2) */
@ -1968,6 +1980,10 @@ static void TestUTextAPI(void) {
TEST_ASSERT_UTEXT(" second<tag-b> third", fields[1]);
TEST_ASSERT(fields[2] == &patternText);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
/* Split with too few output strings available (3) */
status = U_ZERO_ERROR;
@ -1986,6 +2002,9 @@ static void TestUTextAPI(void) {
TEST_ASSERT_UTEXT(" second<tag-b> third", fields[2]);
TEST_ASSERT(fields[3] == &patternText);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
/* Split with just enough output strings available (5) */
status = U_ZERO_ERROR;
@ -2008,6 +2027,9 @@ static void TestUTextAPI(void) {
TEST_ASSERT_UTEXT(" third", fields[4]);
TEST_ASSERT(fields[5] == &patternText);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
/* Split, end of text is a field delimiter. */
status = U_ZERO_ERROR;
@ -2032,10 +2054,14 @@ static void TestUTextAPI(void) {
TEST_ASSERT(fields[8] == NULL);
TEST_ASSERT(fields[9] == &patternText);
}
for(i = 0; i < numFields; i++) {
utext_close(fields[i]);
}
}
uregex_close(re);
}
utext_close(&patternText);
}
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */