summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-13 04:04:33 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-13 04:04:33 +0000
commit7a986b2871afef840c3930f36394d9c639a98875 (patch)
tree01d4c0b9e584f4dfe0e5533bbf8b46335caf671e /hash.c
parent8db3dc39d60870e07cbdfec5e594e0f49b0733c7 (diff)
* hash.c (ruby_setenv): fixed SEGV. [ruby-dev:26186]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index 88b060f11a..05491f0d9d 100644
--- a/hash.c
+++ b/hash.c
@@ -1824,27 +1824,24 @@ ruby_setenv(name, value)
tmpenv[max] = 0;
environ = tmpenv; /* tell exec where it is now */
}
- if (!value) {
- if (environ != origenviron) {
+ if (environ[i]) {
char **envp = origenviron;
while (*envp && *envp != environ[i]) envp++;
if (!*envp)
free(environ[i]);
- }
+ if (!value) {
while (environ[i]) {
environ[i] = environ[i+1];
i++;
}
return;
}
- if (!environ[i]) { /* does not exist yet */
+ }
+ else { /* does not exist yet */
+ if (!value) return;
REALLOC_N(environ, char*, i+2); /* just expand it a bit */
environ[i+1] = 0; /* make sure it's null terminated */
}
- else {
- if (environ[i] != origenviron[i])
- free(environ[i]);
- }
environ[i] = ALLOC_N(char, strlen(name) + strlen(value) + 2);
#ifndef MSDOS
sprintf(environ[i],"%s=%s",name,value); /* all that work just for this */