From 86c98f1f21a1ac1c2d057f1c7747210eab0f1fe3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 9 Oct 2022 21:30:41 +0800 Subject: [PATCH] fix(tsc): fix invalid free --- include/os/osTime.h | 2 +- source/os/src/osTime.c | 3 ++- source/util/src/tlog.c | 14 +------------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/include/os/osTime.h b/include/os/osTime.h index 3daf106ccd..48f046d4d0 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -84,7 +84,7 @@ static FORCE_INLINE int64_t taosGetTimestampNs() { char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm); struct tm *taosLocalTime(const time_t *timep, struct tm *result); -struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz, int dst); +struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst); time_t taosTime(time_t *t); time_t taosMktime(struct tm *timep); diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index ac65e90779..58a09565f9 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -455,7 +455,7 @@ static int isLeapYear(time_t year) { else return 1; } -struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz, int dst) { +struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) { if (result == NULL) { return localtime(timep); } @@ -496,6 +496,7 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, time_t tz } #elif defined(LINUX) time_t secsMin = 60, secsHour = 3600, secsDay = 3600 * 24; + long tz = timezone; time_t t = *timep; t -= tz; /* Adjust for timezone. */ diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index ef21e5b29f..2e2300ba14 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -114,18 +114,6 @@ static void taosCloseLogByFd(TdFilePtr pFile); static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum); static int32_t taosCompressFile(char *srcFileName, char *destFileName); -static FORCE_INLINE long taosGetTimeZone() { -#if defined(__linux__) || defined(__sun) - return timezone; -#else - - // struct timeval tv; - // struct timezone tz; - // gettimeofday(&tv, &tz); - - // return tz.tz_minuteswest * 60L; -#endif -} static FORCE_INLINE void taosUpdateDaylight() { struct tm Tm, *ptm; struct timeval timeSecs; @@ -446,7 +434,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) { taosGetTimeOfDay(&timeSecs); time_t curTime = timeSecs.tv_sec; - ptm = taosLocalTimeNolock(&Tm, &curTime, taosGetTimeZone(), taosGetDaylight()); + ptm = taosLocalTimeNolock(&Tm, &curTime, taosGetDaylight()); return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(), flags); -- GitLab