summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index f3c621acee..39a9a522d7 100644
--- a/hash.c
+++ b/hash.c
@@ -1066,8 +1066,12 @@ ruby_setenv(name, value)
environ = tmpenv; /* tell exec where it is now */
}
if (!value) {
- if (environ[i] != origenviron[i])
- free(environ[i]);
+ if (environ != origenviron) {
+ char **envp = origenviron;
+ while (*envp && *envp != environ[i]) envp++;
+ if (!*envp)
+ free(environ[i]);
+ }
while (environ[i]) {
environ[i] = environ[i+1];
i++;