aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugin_time.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/plugin_time.c b/plugin_time.c
index bae321c..a9cca8f 100644
--- a/plugin_time.c
+++ b/plugin_time.c
@@ -68,6 +68,15 @@ static void my_stftime_tz(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT
char *old_tz;
old_tz = getenv("TZ");
+
+ /*
+ * because the next setenv() call may overwrite that string, we
+ * duplicate it here
+ */
+ if (old_tz) {
+ old_tz = strdup(old_tz);
+ }
+
setenv("TZ", tz, 1);
tzset();
@@ -80,6 +89,8 @@ static void my_stftime_tz(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT
}
tzset();
+ free(old_tz);
+
SetResult(&result, R_STRING, value);
}