summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Pauli <jpauli@php.net>2015-05-12 16:15:10 +0200
committerJulien Pauli <jpauli@php.net>2015-05-12 16:15:10 +0200
commit468e37fe027259fd0a61ac3a84cac1336f768005 (patch)
tree1c98eeb80bffb1b9062d7531e9727328c3d351b1
parentff66eec482563e1366fa418969d6094d4e992f9b (diff)
parent6a819bba40661a9a8d7080994cb2f24b73c5d46c (diff)
downloadphp-git-468e37fe027259fd0a61ac3a84cac1336f768005.tar.gz
fix #66048 for PHP7
* fix-66048: Fix for #66048
-rw-r--r--ext/standard/basic_functions.c4
-rw-r--r--main/main.c39
-rw-r--r--main/php_globals.h2
-rw-r--r--main/php_open_temporary_file.c37
-rw-r--r--main/php_open_temporary_file.h1
5 files changed, 42 insertions, 41 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index b8113fe5ee..5e23fe2ea4 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -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;
}
}
diff --git a/main/main.c b/main/main.c
index 23d6a2c335..37f4d9c238 100644
--- a/main/main.c
+++ b/main/main.c
@@ -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;
diff --git a/main/php_globals.h b/main/php_globals.h
index df2b73200b..315e3b7830 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -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;
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index a88c823eed..edd27a5216 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -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
}
diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h
index 912f4a8adc..3d45fbe332 100644
--- a/main/php_open_temporary_file.h
+++ b/main/php_open_temporary_file.h
@@ -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 */