From 8e192f2f4a5d450105013acf65bb8afd09e097a1 Mon Sep 17 00:00:00 2001 From: Vladimir Weinstein Date: Thu, 28 Nov 2002 08:53:37 +0000 Subject: [PATCH] ICU-2135 fixing memory problems X-SVN-Rev: 10407 --- icu4c/source/common/unorm.cpp | 14 +++++++------- icu4c/source/test/cintltst/cmsgtst.c | 7 ++++--- icu4c/source/test/cintltst/nucnvtst.c | 3 +++ icu4c/source/test/cintltst/usrchtst.c | 8 +++++++- icu4c/source/test/intltest/apicoll.cpp | 1 + icu4c/source/test/intltest/icusvtst.cpp | 8 ++++++++ icu4c/source/test/intltest/tzregts.cpp | 6 ++++-- 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/icu4c/source/common/unorm.cpp b/icu4c/source/common/unorm.cpp index cbfe84d849c..e10a300674c 100644 --- a/icu4c/source/common/unorm.cpp +++ b/icu4c/source/common/unorm.cpp @@ -2940,12 +2940,12 @@ unorm_previous(UCharIterator *src, UBool doNormalize, UBool *pNeededToNormalize, UErrorCode *pErrorCode) { UChar stackBuffer[100]; - UChar *buffer; - IsPrevBoundaryFn *isPreviousBoundary; - uint32_t mask; - int32_t startIndex, bufferLength, bufferCapacity, destLength; - int32_t c, c2; - UChar minC; + UChar *buffer=NULL; + IsPrevBoundaryFn *isPreviousBoundary=NULL; + uint32_t mask=0; + int32_t startIndex=0, bufferLength=0, bufferCapacity=0, destLength=0; + int32_t c=0, c2=0; + UChar minC=0; /* check argument values */ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { @@ -3031,7 +3031,7 @@ unorm_previous(UCharIterator *src, if(pNeededToNormalize!=0 && U_SUCCESS(*pErrorCode)) { *pNeededToNormalize= (UBool)(destLength!=bufferLength || - 0!=uprv_memcmp(dest, buffer, destLength*U_SIZEOF_UCHAR)); + 0!=uprv_memcmp(dest, buffer+startIndex, destLength*U_SIZEOF_UCHAR)); } } else { /* just copy the source characters */ diff --git a/icu4c/source/test/cintltst/cmsgtst.c b/icu4c/source/test/cintltst/cmsgtst.c index 6a6f6646ff0..d52c4513e80 100644 --- a/icu4c/source/test/cintltst/cmsgtst.c +++ b/icu4c/source/test/cintltst/cmsgtst.c @@ -342,7 +342,7 @@ static void TestNewFormatAndParseAPI(void) UDate d1,d; UDateFormat *def1; UErrorCode status = U_ZERO_ERROR; - double value; + double value = 0.0; UChar ret[30]; UParseError parseError; UMessageFormat* fmt = NULL; @@ -437,13 +437,14 @@ static void TestSampleFormatAndParseWithError(void) UChar *result, *tzID, *str; UChar pattern[100]; + UChar expected[100]; int32_t resultLengthOut, resultlength; UCalendar *cal; UDate d1,d; UDateFormat *def1; UErrorCode status = U_ZERO_ERROR; - double value; + double value = 0.0; UChar ret[30]; UParseError parseError; @@ -534,7 +535,7 @@ static void TestSampleFormatAndParse() UDate d1,d; UDateFormat *def1; UErrorCode status = U_ZERO_ERROR; - double value; + double value = 0.0; UChar ret[30]; log_verbose("Testing format and parse\n"); diff --git a/icu4c/source/test/cintltst/nucnvtst.c b/icu4c/source/test/cintltst/nucnvtst.c index 757fa1c18d8..49754999f56 100644 --- a/icu4c/source/test/cintltst/nucnvtst.c +++ b/icu4c/source/test/cintltst/nucnvtst.c @@ -3932,6 +3932,9 @@ static void TestJitterbug2411(){ log_err("iso-2022-kr_1 cannot handle multiple escape sequences : %s\n", u_errorName(errorCode)); return; } + + ucnv_close(kr); + ucnv_close(kr1); } diff --git a/icu4c/source/test/cintltst/usrchtst.c b/icu4c/source/test/cintltst/usrchtst.c index 7ccfd5ee1e5..23f24e46b0b 100644 --- a/icu4c/source/test/cintltst/usrchtst.c +++ b/icu4c/source/test/cintltst/usrchtst.c @@ -292,6 +292,7 @@ static void TestInitialization(void) UErrorCode status = U_ZERO_ERROR; UChar pattern[512]; const UChar text[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66}; + int32_t i = 0; UStringSearch *result; /* simple test on the pattern ce construction */ @@ -306,7 +307,10 @@ static void TestInitialization(void) usearch_close(result); /* testing if an extremely large pattern will fail the initialization */ - uprv_memset(pattern, 0x41, 512); + for(i = 0; i < 512; i++) { + pattern[i] = 0x41; + } + /*uprv_memset(pattern, 0x41, 512);*/ result = usearch_openFromCollator(pattern, 512, text, 3, EN_US_, NULL, &status); if (U_FAILURE(status)) { @@ -1026,6 +1030,8 @@ static void TestGetSetOffset(void) UChar text[128]; UErrorCode status = U_ZERO_ERROR; UStringSearch *strsrch; + memset(pattern, 0, 32*sizeof(UChar)); + memset(text, 0, 128*sizeof(UChar)); open(); if (usearch_getOffset(NULL) != USEARCH_DONE) { diff --git a/icu4c/source/test/intltest/apicoll.cpp b/icu4c/source/test/intltest/apicoll.cpp index bacc481424e..2edb1807369 100644 --- a/icu4c/source/test/intltest/apicoll.cpp +++ b/icu4c/source/test/intltest/apicoll.cpp @@ -1738,6 +1738,7 @@ void CollationAPITest::TestUClassID() if (id != 0) { errln("Dynamic class id for CollationElementIterator should be 0"); } + delete key; delete iter; delete coll; } diff --git a/icu4c/source/test/intltest/icusvtst.cpp b/icu4c/source/test/intltest/icusvtst.cpp index a85251baea4..6d4d59d045d 100644 --- a/icu4c/source/test/intltest/icusvtst.cpp +++ b/icu4c/source/test/intltest/icusvtst.cpp @@ -1097,6 +1097,7 @@ void ICUServiceTest::testLocale() { lkey->fallback(); logln("lkey descriptor 3: " + lkey->currentDescriptor(result)); result.remove(); + delete lkey; // tentatively weiv } { @@ -1163,6 +1164,13 @@ void ICUServiceTest::testLocale() { errln("could not create available locales"); } } + delete one; + delete two; + delete root; + delete german; + delete germany; + delete japanese; + delete japan; } class WrapFactory : public ICUServiceFactory { diff --git a/icu4c/source/test/intltest/tzregts.cpp b/icu4c/source/test/intltest/tzregts.cpp index be172c9b83f..64c607b4271 100644 --- a/icu4c/source/test/intltest/tzregts.cpp +++ b/icu4c/source/test/intltest/tzregts.cpp @@ -481,8 +481,10 @@ void TimeZoneRegressionTest:: Test4151406() { max = count; logln(hname + ' ' + count + ((count > 0) ? (" e.g. " + *ids->snext(ec)) : UnicodeString(""))); - // delete [] ids; - uprv_free(ids); + // weiv 11/27/2002: why uprv_free? This should be a delete + delete ids; + //delete [] ids; + //uprv_free(ids); /*} catch (Exception e) { errln(hname + ' ' + "Fail: " + e); }*/