From: Sascha Schumann Date: Fri, 3 Aug 2001 09:50:38 +0000 (+0000) Subject: Don't copy the strtok parameter X-Git-Tag: PRE_ENGINE2_SPLIT~102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f6ed403fde48991afd66ea5eb93573f99b27e34a;p=php Don't copy the strtok parameter --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 8cea4eeac0..e136a4298c 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -849,6 +849,7 @@ PHP_RINIT_FUNCTION(basic) { memset(BG(strtok_table), 0, 256); BG(strtok_string) = NULL; + BG(strtok_zval) = NULL; BG(locale_string) = NULL; BG(user_compare_func_name) = NULL; BG(array_walk_func_name) = NULL; @@ -892,8 +893,10 @@ PHP_RINIT_FUNCTION(basic) PHP_RSHUTDOWN_FUNCTION(basic) { - STR_FREE(BG(strtok_string)); + if (BG(strtok_zval)) + zval_ptr_dtor(BG(strtok_zval)); BG(strtok_string) = NULL; + BG(strtok_zval) = NULL; #ifdef HAVE_PUTENV zend_hash_destroy(&BG(putenv_ht)); #endif diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 30b71de657..900a1b13f5 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -141,6 +141,7 @@ typedef signed int php_int32; typedef struct { HashTable *user_shutdown_function_names; HashTable putenv_ht; + zval **strtok_zval; char *strtok_string; char *locale_string; char *strtok_last; diff --git a/ext/standard/string.c b/ext/standard/string.c index c62d78a120..ad1a246db3 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -829,8 +829,12 @@ PHP_FUNCTION(strtok) tok = args[1]; convert_to_string_ex(str); - STR_FREE(BG(strtok_string)); - BG(strtok_last) = BG(strtok_string) = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str)); + zval_add_ref(str); + if (BG(strtok_zval)) + zval_ptr_dtor(BG(strtok_zval)); + BG(strtok_zval) = str; + + BG(strtok_last) = BG(strtok_string) = Z_STRVAL_PP(str); BG(strtok_len) = Z_STRLEN_PP(str); break; }