ICU-1880 Fix memory leaks

X-SVN-Rev: 8679
This commit is contained in:
George Rhoten 2002-05-23 17:18:05 +00:00
parent bca746dcf9
commit 394ebf6ffe
3 changed files with 14 additions and 19 deletions

View file

@ -7,12 +7,9 @@
/* Created by weiv 05/09/2002 */
#include "resbtddr.h"
#include "cmemory.h"
#include "cstring.h"
// TODO: this is bad - be smarter, although if on level with IntlTest, it might be good
static char* _testDataPath=NULL;
ResBundTestDataDriver::ResBundTestDataDriver(const char* testName, UErrorCode &status)
: TestDataDriver(testName),
fTestBundle(NULL),
@ -24,7 +21,8 @@ ResBundTestDataDriver::ResBundTestDataDriver(const char* testName, UErrorCode &s
fTestSettings(NULL),
fCurrentSettings(NULL),
fTestCases(NULL),
fCurrentCase(NULL)
fCurrentCase(NULL),
tdpath(NULL)
{
fNumberOfTests = 0;
fDataTestValid = TRUE;
@ -54,6 +52,7 @@ ResBundTestDataDriver::~ResBundTestDataDriver()
ures_close(fCurrentSettings);
ures_close(fTestCases);
ures_close(fCurrentCase);
uprv_free(tdpath);
}
void
@ -186,11 +185,8 @@ ResBundTestDataDriver::getTestBundle(const char* bundleName)
UErrorCode status = U_ZERO_ERROR;
UResourceBundle *testBundle = NULL;
const char* icu_data = (char*)loadTestData(status);
char testBundlePath[256] = {'\0'};
strcpy(testBundlePath, icu_data);
//strcat(testBundlePath, U_FILE_SEP_STRING".."U_FILE_SEP_STRING"build"U_FILE_SEP_STRING);
if (testBundle == NULL) {
testBundle = ures_openDirect(testBundlePath, bundleName, &status);
testBundle = ures_openDirect(icu_data, bundleName, &status);
if (status != U_ZERO_ERROR) {
errln(UnicodeString("Failed: could not load test data from resourcebundle: ") + UnicodeString(bundleName));
fDataTestValid = FALSE;
@ -199,16 +195,15 @@ ResBundTestDataDriver::getTestBundle(const char* bundleName)
return testBundle;
}
const char*
char*
ResBundTestDataDriver::loadTestData(UErrorCode& err){
const char* directory=NULL;
UResourceBundle* test =NULL;
char* tdpath=NULL;
const char* tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
if( _testDataPath == NULL){
if( tdpath == NULL){
directory= u_getDataDirectory();
tdpath = new char[(( strlen(directory) * strlen(tdrelativepath)) + 10)];//(char*) ctst_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10));
tdpath = (char*) uprv_malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 10));
/* u_getDataDirectory shoul return \source\data ... set the
@ -242,12 +237,10 @@ ResBundTestDataDriver::loadTestData(UErrorCode& err){
return "";
}
ures_close(test);
_testDataPath = tdpath;
return _testDataPath;
return tdpath;
}
ures_close(test);
_testDataPath = tdpath;
return _testDataPath;
return tdpath;
}
return _testDataPath;
return tdpath;
}

View file

@ -32,7 +32,7 @@ public:
virtual int32_t getNextTestCase(UnicodeString * testCase, int32_t capacity, UErrorCode &status);
private:
UResourceBundle *getTestBundle(const char* bundleName);
const char* loadTestData(UErrorCode& err);
char* loadTestData(UErrorCode& err);
UBool initSettingsAndCases(UErrorCode &status);
int32_t fillSettingsArrays(UResourceBundle *res, const char **names, UnicodeString * values, int32_t capacity, UErrorCode &status);
@ -47,6 +47,7 @@ private:
UResourceBundle *fTestCases;
UResourceBundle *fCurrentCase;
UBool fDataTestValid;
char *tdpath;
};
#endif

View file

@ -340,6 +340,7 @@ StringCaseTest::TestTitleCasing() {
errln("error: TestTitleCasing() got a wrong result for test case from casing.res");
}
}
ubrk_close(iter);
}
}
delete driver;