Browse Source

ENGINE-951: refactored timegm_with_gmtoff to remove mem leak

master
Krista Bennett 3 months ago
parent
commit
e217dc2392
1 changed files with 16 additions and 15 deletions
  1. +16
    -15
      src/timestamp.c

+ 16
- 15
src/timestamp.c View File

@ -15,23 +15,24 @@
DYNAMIC_API time_t timegm_with_gmtoff(const timestamp* ts)
{
if (!ts)
return -1;
timestamp *_ts = timestamp_dup(ts);
if (!_ts)
return -1;
const time_t raw_time = timegm(_ts);
if(raw_time==-1)
return -1;
free_timestamp(_ts);
return raw_time - ts->tm_gmtoff;
time_t retval = -1;
timestamp *_ts = NULL;
if (ts) {
_ts = timestamp_dup(ts);
if (_ts) {
const time_t raw_time = timegm(_ts);
if (raw_time != -1) {
retval = raw_time - ts->tm_gmtoff;
}
}
}
free_timestamp(_ts); // Safe if NULL
return retval;
}
DYNAMIC_API timestamp * new_timestamp(time_t clock)
{
timestamp *ts = calloc(1, sizeof(timestamp));


Loading…
Cancel
Save