This commit is contained in:
Julien Pauli 2015-04-29 14:35:35 +02:00
parent c6b986b4e7
commit 6a819bba40
5 changed files with 42 additions and 41 deletions

View 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;
}
}

View 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;

View 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;

View 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
}

View 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 */