Skip to content

Commit 6f4ae12

Browse files
committed
Fix memory issue because of impacting with TZ
1 parent ccf09e1 commit 6f4ae12

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

library/Java/Text/SimpleDateFormat/SimpleDateFormat.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ void SimpleDateFormat::setTimeZone(const TimeZone &timeZone) {
4343
String SimpleDateFormat::format(const Date &date) {
4444
String tz = String("TZ=") + this->timeZone.getID();
4545
putenv(tz.toCharPointer());
46-
4746
std::time_t current_time;
4847
std::time(&current_time);
4948
struct std::tm *timeinfo = std::localtime(&current_time);
5049
long offset = timeinfo->tm_gmtoff;
51-
50+
unsetenv("TZ");
5251
size_t bufferLength = 80;
5352
string buffer = (string) calloc(bufferLength, sizeof(char));
5453
time_t timestamp = (time_t) ((date.getTime() / 1000) + offset);

library/Java/Util/Date/Date.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,14 @@ long Date::parse(String inputString) {
428428
long Date::getOffsetFromUTC() {
429429
long currentTime;
430430
struct tm * timeInfo;
431-
432-
time( &currentTime );
431+
time(&currentTime);
433432
timeInfo = gmtime (&currentTime);
434433
time_t utc = mktime(timeInfo);
435434
timeInfo = localtime(&currentTime);
436435
time_t local = mktime(timeInfo);
437436

438437
// Get offset in hours from UTC
439438
double offsetFromUTC = difftime(utc, local); // HOUR_IN_SECOND;
440-
441439
return (long) offsetFromUTC;
442440
}
443441

@@ -527,6 +525,7 @@ void Date::initializeDate(int year, int month, int date,
527525

528526
this->timer = mktime(&localTimer);
529527
this->localTimer = localtime(&this->timer);
528+
this->updateDateStatus();
530529
}
531530

532531
void Date::initializeDate(long timestamp) {
@@ -549,7 +548,6 @@ String Date::timeToString(String pattern, tm *timeManagement) const {
549548
long Date::getUTCTime(long timer) {
550549
tm tempTimer = {0};
551550
tm *utcTimer = gmtime_r(&timer, &tempTimer);
552-
553551
return mktime(utcTimer);
554552
}
555553

0 commit comments

Comments
 (0)