diff options
author | Nuno Lopes <nlopess@php.net> | 2006-06-17 11:08:05 +0000 |
---|---|---|
committer | Nuno Lopes <nlopess@php.net> | 2006-06-17 11:08:05 +0000 |
commit | 6509311ebbcf52badde5cabc93f7849328be53d5 (patch) | |
tree | 389b7139f23c538e882c20f45803cd3c62200683 | |
parent | aa4881437863af5a800b6b3a31fbb2db261c670e (diff) | |
download | php-git-6509311ebbcf52badde5cabc93f7849328be53d5.tar.gz |
plug memory leak in sapi_putenv, by using setenv(), that doesnt need any malloc
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | sapi/cgi/cgi_main.c | 23 |
2 files changed, 22 insertions, 2 deletions
diff --git a/configure.in b/configure.in index e4caa4aa24..0dcaee6dc8 100644 --- a/configure.in +++ b/configure.in @@ -505,6 +505,7 @@ scandir \ setitimer \ setlocale \ localeconv \ +setenv \ setpgid \ setsockopt \ setvbuf \ diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index c58afaae33..8ee624ef89 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -405,6 +405,18 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) return fcgi_putenv(request, name, name_len, value); } #endif +#if HAVE_SETENV + if (value) { + setenv(name, value, 1); + } +#endif +#if HAVE_UNSETENV + if (!value) { + unsetenv(name); + } +#endif + +#if !HAVE_SETENV || !HAVE_UNSETENV /* if cgi, or fastcgi and not found in fcgi env check the regular environment this leaks, but it's only cgi anyway, we'll fix @@ -415,12 +427,19 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) if (buf == NULL) { return getenv(name); } +#endif +#if !HAVE_SETENV if (value) { len = snprintf(buf, len - 1, "%s=%s", name, value); - } else { + putenv(buf); + } +#endif +#if !HAVE_UNSETENV + if (!value) { len = snprintf(buf, len - 1, "%s=", name); + putenv(buf); } - putenv(buf); +#endif return getenv(name); } |