ICU-5029 Fix some memory problems

X-SVN-Rev: 19070
This commit is contained in:
George Rhoten 2006-02-06 18:21:06 +00:00
parent b452ca48e6
commit 8bb51a8617
2 changed files with 14 additions and 7 deletions

View file

@ -90,9 +90,10 @@ UnicodeString *getTimeDateFormat(const Calendar *cal, const Locale *locale, UErr
Win32DateFormat::Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status)
: DateFormat(), fDateTimeMsg(NULL), fTimeStyle(timeStyle), fDateStyle(dateStyle), fLocale(&locale), fZoneID(NULL)
{
if (!U_FAILURE(status)) {
if (U_SUCCESS(status)) {
fLCID = locale.getLCID();
fTZI = new TIME_ZONE_INFORMATION();
fTZI = NEW_ARRAY(TIME_ZONE_INFORMATION, 1);
uprv_memset(fTZI, 0, sizeof(TIME_ZONE_INFORMATION));
adoptCalendar(Calendar::createInstance(locale, status));
}
}
@ -105,25 +106,26 @@ Win32DateFormat::Win32DateFormat(const Win32DateFormat &other)
Win32DateFormat::~Win32DateFormat()
{
delete fCalendar;
delete fTZI;
// delete fCalendar;
uprv_free(fTZI);
delete fDateTimeMsg;
}
Win32DateFormat &Win32DateFormat::operator=(const Win32DateFormat &other)
{
// The following handles fCalendar
DateFormat::operator=(other);
delete fCalendar;
// delete fCalendar;
this->fDateTimeMsg = other.fDateTimeMsg;
this->fTimeStyle = other.fTimeStyle;
this->fDateStyle = other.fDateStyle;
this->fLCID = other.fLCID;
this->fCalendar = other.fCalendar->clone();
// this->fCalendar = other.fCalendar->clone();
this->fZoneID = other.fZoneID;
this->fTZI = new TIME_ZONE_INFORMATION();
this->fTZI = NEW_ARRAY(TIME_ZONE_INFORMATION, 1);
*this->fTZI = *other.fTZI;
return *this;

View file

@ -76,6 +76,7 @@ void Win32DateTimeTest::testLocales(TestLog *log)
const TimeZone *tz = TimeZone::createDefault();
TIME_ZONE_INFORMATION tzi;
uprv_memset(&tzi, 0, sizeof(tzi));
tz->getID(zoneID);
if (! uprv_getWindowsTimeZoneInfo(&tzi, zoneID.getBuffer(), zoneID.length())) {
UBool found = FALSE;
@ -177,9 +178,13 @@ void Win32DateTimeTest::testLocales(TestLog *log)
log->errln("Time format error for locale " + baseName + ": expected \"" + expected +
"\" got \"" + utBuffer + "\"");
}
delete wbf;
delete wdf;
delete wtf;
}
Win32Utilities::freeLocales(lcidRecords);
delete tz;
}
#endif /* #if !UCONFIG_NO_FORMATTING */