]> granicus.if.org Git - php/commitdiff
Fix for #66048
authorJulien Pauli <jpauli@php.net>
Wed, 29 Apr 2015 12:35:35 +0000 (14:35 +0200)
committerJulien Pauli <jpauli@php.net>
Tue, 12 May 2015 14:15:01 +0000 (16:15 +0200)
ext/standard/basic_functions.c
main/main.c
main/php_globals.h
main/php_open_temporary_file.c
main/php_open_temporary_file.h

index b8113fe5ee44feecb49be0f0c845abead6fab7a0..5e23fe2ea492b628b915494928cb773f1b263db9 100644 (file)
@@ -4740,11 +4740,11 @@ PHP_FUNCTION(error_clear_last)
                PG(last_error_type) = 0;
                PG(last_error_lineno) = 0;
 
-               free(PG(last_error_message));
+               efree(PG(last_error_message));
                PG(last_error_message) = NULL;
 
                if (PG(last_error_file)) {
-                       free(PG(last_error_file));
+                       efree(PG(last_error_file));
                        PG(last_error_file) = NULL;
                }
        }
index 23d6a2c335a832b0b248159f9600afbe2f5974ef..37f4d9c238e6c9035be2211d5356d634282927e7 100644 (file)
@@ -990,11 +990,11 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
                HANDLE_BLOCK_INTERRUPTIONS();
 #endif
                if (PG(last_error_message)) {
-                       free(PG(last_error_message));
+                       efree(PG(last_error_message));
                        PG(last_error_message) = NULL;
                }
                if (PG(last_error_file)) {
-                       free(PG(last_error_file));
+                       efree(PG(last_error_file));
                        PG(last_error_file) = NULL;
                }
 #ifdef ZEND_SIGNALS
@@ -1004,8 +1004,8 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
                        error_filename = "Unknown";
                }
                PG(last_error_type) = type;
-               PG(last_error_message) = strdup(buffer);
-               PG(last_error_file) = strdup(error_filename);
+               PG(last_error_message) = estrdup(buffer);
+               PG(last_error_file) = estrdup(error_filename);
                PG(last_error_lineno) = error_lineno;
        }
 
@@ -1394,6 +1394,25 @@ static zval *php_get_configuration_directive_for_zend(zend_string *name)
 }
 /* }}} */
 
+/* {{{ php_free_request_globals
+ */
+static void php_free_request_globals(void)
+{
+       if (PG(last_error_message)) {
+               efree(PG(last_error_message));
+               PG(last_error_message) = NULL;
+       }
+       if (PG(last_error_file)) {
+               efree(PG(last_error_file));
+               PG(last_error_file) = NULL;
+       }
+       if (PG(php_sys_temp_dir)) {
+               efree(PG(php_sys_temp_dir));
+               PG(php_sys_temp_dir) = NULL;
+       }
+}
+/* }}} */
+
 /* {{{ php_message_handler_for_zend
  */
 static void php_message_handler_for_zend(zend_long message, const void *data)
@@ -1792,15 +1811,8 @@ void php_request_shutdown(void *dummy)
                }
        } zend_end_try();
 
-       /* 8. free last error information */
-       if (PG(last_error_message)) {
-               free(PG(last_error_message));
-               PG(last_error_message) = NULL;
-       }
-       if (PG(last_error_file)) {
-               free(PG(last_error_file));
-               PG(last_error_file) = NULL;
-       }
+       /* 8. free request-bound globals */
+       php_free_request_globals();
 
        /* 9. Shutdown scanner/executor/compiler and restore ini entries */
        zend_deactivate();
@@ -2350,7 +2362,6 @@ void php_module_shutdown(void)
 #endif
 
        php_output_shutdown();
-       php_shutdown_temporary_directory();
 
        module_initialized = 0;
 
index df2b73200bdc6de9fad618de375b0bafa1c622fa..315e3b78309a44618fe5851f9a68e61dfa1ff5cc 100644 (file)
@@ -142,6 +142,8 @@ struct _php_core_globals {
        char *last_error_file;
        int  last_error_lineno;
 
+       char *php_sys_temp_dir;
+
        char *disable_functions;
        char *disable_classes;
        zend_bool allow_url_include;
index a88c823eedba992c9f6ae91b07513561123930c9..edd27a5216966daca0d3286f7b7cbf80856106cf 100644 (file)
@@ -171,25 +171,14 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
 }
 /* }}} */
 
-/* Cache the chosen temporary directory. */
-static char* temporary_directory;
-
-PHPAPI void php_shutdown_temporary_directory(void)
-{
-       if (temporary_directory) {
-               free(temporary_directory);
-               temporary_directory = NULL;
-       }
-}
-
 /*
  *  Determine where to place temporary files.
  */
 PHPAPI const char* php_get_temporary_directory(void)
 {
        /* Did we determine the temporary directory already? */
-       if (temporary_directory) {
-               return temporary_directory;
+       if (PG(php_sys_temp_dir)) {
+               return PG(php_sys_temp_dir);
        }
 
        /* Is there a temporary directory "sys_temp_dir" in .ini defined? */
@@ -198,11 +187,11 @@ PHPAPI const char* php_get_temporary_directory(void)
                if (sys_temp_dir) {
                        int len = (int)strlen(sys_temp_dir);
                        if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
-                               temporary_directory = zend_strndup(sys_temp_dir, len - 1);
-                               return temporary_directory;
+                               PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1);
+                               return PG(php_sys_temp_dir);
                        } else if (len >= 1 && sys_temp_dir[len - 1] != DEFAULT_SLASH) {
-                               temporary_directory = zend_strndup(sys_temp_dir, len);
-                               return temporary_directory;
+                               PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len);
+                               return PG(php_sys_temp_dir);
                        }
                }
        }
@@ -232,24 +221,24 @@ PHPAPI const char* php_get_temporary_directory(void)
                        int len = strlen(s);
 
                        if (s[len - 1] == DEFAULT_SLASH) {
-                               temporary_directory = zend_strndup(s, len - 1);
+                               PG(php_sys_temp_dir) = estrndup(s, len - 1);
                        } else {
-                               temporary_directory = zend_strndup(s, len);
+                               PG(php_sys_temp_dir) = estrndup(s, len);
                        }
 
-                       return temporary_directory;
+                       return PG(php_sys_temp_dir);
                }
        }
 #ifdef P_tmpdir
        /* Use the standard default temporary directory. */
        if (P_tmpdir) {
-               temporary_directory = strdup(P_tmpdir);
-               return temporary_directory;
+               PG(php_sys_temp_dir) = estrdup(P_tmpdir);
+               return PG(php_sys_temp_dir);
        }
 #endif
        /* Shouldn't ever(!) end up here ... last ditch default. */
-       temporary_directory = strdup("/tmp");
-       return temporary_directory;
+       PG(php_sys_temp_dir) = estrdup("/tmp");
+       return PG(php_sys_temp_dir);
 #endif
 }
 
index 912f4a8adc45293e5bc9465712bb756614893c0f..3d45fbe332f1a7a43c5b6a7270818f1edd673d4c 100644 (file)
@@ -26,7 +26,6 @@ PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, zend_stri
 PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, zend_bool open_basedir_check);
 PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, zend_string **opened_path_p);
 PHPAPI const char *php_get_temporary_directory(void);
-PHPAPI void php_shutdown_temporary_directory(void);
 END_EXTERN_C()
 
 #endif /* PHP_OPEN_TEMPORARY_FILE_H */