php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #64544
Patch bug64544.patch revision 2013-03-29 03:52 UTC by laruence@php.net
revision 2013-03-29 03:11 UTC by laruence@php.net

Patch bug64544.patch for CGI/CLI related Bug #64544

Patch version 2013-03-29 03:52 UTC

Return to Bug #64544 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: laruence@php.net

diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 4b8bae7..7290523 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -1402,7 +1402,7 @@ out:
 	 * Do not move this de-initialization. It needs to happen right before
 	 * exiting.
 	 */
-        cleanup_ps_args(argv);
+	cleanup_ps_args(argv);
 	exit(exit_status);
 }
 /* }}} */
diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c
index a2e47f0..2845370 100644
--- a/sapi/cli/ps_title.c
+++ b/sapi/cli/ps_title.c
@@ -124,6 +124,7 @@ static size_t ps_buffer_cur_len; /* actual string length in ps_buffer */
 static int save_argc;
 static char** save_argv;
 
+static char **new_environ, **frozen_environ;
 
 /*
  * Call this method early, before any code has used the original argv passed in
@@ -145,7 +146,6 @@ char** save_ps_args(int argc, char** argv)
     {
         char* end_of_area = NULL;
         int non_contiguous_area = 0;
-        char** new_environ;
         int i;
 
         /*
@@ -178,6 +178,7 @@ char** save_ps_args(int argc, char** argv)
          * move the environment out of the way
          */
         new_environ = (char **) malloc((i + 1) * sizeof(char *));
+        frozen_environ = (char **) malloc((i + 1) * sizeof(char *));
         if (!new_environ)
             goto clobber_error;
         for (i = 0; environ[i] != NULL; i++)
@@ -188,7 +189,7 @@ char** save_ps_args(int argc, char** argv)
         }
         new_environ[i] = NULL;
         environ = new_environ;
-
+        memcpy((char *)frozen_environ, (char *)new_environ, sizeof(char *) * (i + 1));
     }
 #endif /* PS_USE_CLOBBER_ARGV */
 
@@ -405,9 +406,10 @@ void cleanup_ps_args(char **argv)
 #ifdef PS_USE_CLOBBER_ARGV
         {
             int i;
-            for (i = 0; environ[i] != NULL; i++)
-                free(environ[i]);
-            free(environ);
+            for (i = 0; frozen_environ[i] != NULL; i++)
+                free(frozen_environ[i]);
+            free(frozen_environ);
+            free(new_environ);
         }
 #endif /* PS_USE_CLOBBER_ARGV */
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 08:01:27 2024 UTC