diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-04-04 21:58:46 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-04-04 21:58:46 +0900 |
| commit | d97a37eb7b4fe52bb1b16bb6f7410fbae85e3809 (patch) | |
| tree | f416da0238869bf4ab96fb16be68a1aed8a7819f /mrbgems/mruby-time | |
| parent | e1e888e354abbd7fc3b14302675a5ef6b0dde8af (diff) | |
| download | mruby-d97a37eb7b4fe52bb1b16bb6f7410fbae85e3809.tar.gz mruby-d97a37eb7b4fe52bb1b16bb6f7410fbae85e3809.zip | |
fix possible memory leak in mruby-time gem
Diffstat (limited to 'mrbgems/mruby-time')
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index b9746b79e..19ce32832 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -213,19 +213,21 @@ static struct mrb_time* time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone) { struct mrb_time *tm; + time_t tsec; - tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time)); if (sizeof(time_t) == 4 && (sec > (double)INT32_MAX || (double)INT32_MIN > sec)) { goto out_of_range; } if (sizeof(time_t) == 8 && (sec > (double)INT64_MAX || (double)INT64_MIN > sec)) { goto out_of_range; } - tm->sec = (time_t)sec; - if ((sec > 0 && tm->sec < 0) || (sec < 0 && (double)tm->sec > sec)) { + tsec = (time_t)sec; + if ((sec > 0 && tsec < 0) || (sec < 0 && (double)tsec > sec)) { out_of_range: mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, sec)); } + tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time)); + tm->sec = tsec; tm->usec = (time_t)llround((sec - tm->sec) * 1.0e6 + usec); while (tm->usec < 0) { tm->sec--; |
