diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index e8141d37ff1c5..387948613e11c 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -43,12 +43,15 @@ timegm(struct tm *tm) char *tz; tz = getenv("TZ"); + if (tz) + tz = strdup(tz); setenv("TZ", "", 1); tzset(); ret = mktime(tm); - if (tz) + if (tz) { setenv("TZ", tz, 1); - else + free(tz); + } else unsetenv("TZ"); tzset(); return ret;