From 2353dfaf78cea7c74c7442eeb5f632701217dd96 Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Mon, 28 Jul 2003 23:48:47 +0000 Subject: [PATCH] ICU-3050 fix memory leaks in the test X-SVN-Rev: 12705 --- icu4c/source/test/intltest/idnaref.cpp | 15 ------------- icu4c/source/test/intltest/testidna.cpp | 28 ++++++++++++++++++++----- icu4c/source/test/intltest/testidna.h | 2 ++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/icu4c/source/test/intltest/idnaref.cpp b/icu4c/source/test/intltest/idnaref.cpp index 52647ac310c..3d7df037c21 100644 --- a/icu4c/source/test/intltest/idnaref.cpp +++ b/icu4c/source/test/intltest/idnaref.cpp @@ -43,21 +43,6 @@ static const UChar ACE_PREFIX[] ={ 0x0058,0x004E,0x002d,0x002d } ; #define FULL_STOP 0x002E -NamePrepTransform* TestIDNA::prep = NULL; - -NamePrepTransform* TestIDNA::getInstance(UErrorCode& status){ - if(TestIDNA::prep == NULL){ - UParseError parseError; - TestIDNA::prep = NamePrepTransform::createInstance(parseError, status); - if(TestIDNA::prep ==NULL){ - //status = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - } - return TestIDNA::prep; - -} - inline static UBool startsWithPrefix(const UChar* src , int32_t srcLength){ UBool startsWithPrefix = TRUE; diff --git a/icu4c/source/test/intltest/testidna.cpp b/icu4c/source/test/intltest/testidna.cpp index 5e24738d3bf..6ddb4de5569 100644 --- a/icu4c/source/test/intltest/testidna.cpp +++ b/icu4c/source/test/intltest/testidna.cpp @@ -615,7 +615,9 @@ void TestIDNA::debug(const UChar* src, int32_t srcLength, int32_t options){ errln("Failed. Expected: " + prettify(UnicodeString(transOut, transOutLength)) + " Got: " + prettify(UnicodeString(prepOut,prepOutLength))); } - + uprv_free(transOut); + uprv_free(prepOut); + delete trans; } @@ -1572,8 +1574,6 @@ void TestIDNA::TestIDNAMonkeyTest(){ debug(source.getBuffer(),source.length(),UIDNA_ALLOW_UNASSIGNED); source.releaseBuffer(); - delete TestIDNA::prep; - TestIDNA::prep = NULL; } void TestIDNA::TestCompareReferenceImpl(){ @@ -1617,12 +1617,30 @@ void TestIDNA::TestRefIDNA(){ "idnaref_IDNToUnicode",idnaref_IDNToUnicode ); testChaining("idnaref_toASCII",idnaref_toASCII, "idnaref_toUnicode", idnaref_toUnicode); - delete TestIDNA::prep; - TestIDNA::prep = NULL; } void TestIDNA::TestDataFile(){ testData(*this); } +TestIDNA::~TestIDNA(){ + if(prep!=NULL){ + delete prep; + prep = NULL; + } +} +NamePrepTransform* TestIDNA::prep = NULL; + +NamePrepTransform* TestIDNA::getInstance(UErrorCode& status){ + if(TestIDNA::prep == NULL){ + UParseError parseError; + TestIDNA::prep = NamePrepTransform::createInstance(parseError, status); + if(TestIDNA::prep ==NULL){ + //status = U_MEMORY_ALLOCATION_ERROR; + return NULL; + } + } + return TestIDNA::prep; + +} #endif /* #if !UCONFIG_NO_IDNA */ diff --git a/icu4c/source/test/intltest/testidna.h b/icu4c/source/test/intltest/testidna.h index 4b866fc3b25..cba80441093 100644 --- a/icu4c/source/test/intltest/testidna.h +++ b/icu4c/source/test/intltest/testidna.h @@ -66,6 +66,8 @@ public: void TestConformance(); static NamePrepTransform* getInstance(UErrorCode& status); static NamePrepTransform* prep; + ~TestIDNA(); + private: void testToASCII(const char* testName, TestFunc func); void testToUnicode(const char* testName, TestFunc func);