@@ -130,7 +130,7 @@ static void spl_filesystem_object_free_storage(zend_object *object) /* {{{ */
130
130
break ;
131
131
case SPL_FS_FILE :
132
132
if (intern -> u .file .open_mode ) {
133
- efree (intern -> u .file .open_mode );
133
+ zend_string_release (intern -> u .file .open_mode );
134
134
}
135
135
if (intern -> orig_path ) {
136
136
zend_string_release (intern -> orig_path );
@@ -304,21 +304,23 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
304
304
intern -> type = SPL_FS_FILE ;
305
305
php_stat (intern -> file_name , FS_IS_DIR , & tmp );
306
306
if (Z_TYPE (tmp ) == IS_TRUE ) {
307
+ zend_string_release (intern -> u .file .open_mode );
307
308
intern -> u .file .open_mode = NULL ;
308
309
intern -> file_name = NULL ;
309
310
zend_throw_exception_ex (spl_ce_LogicException , 0 , "Cannot use SplFileObject with directories" );
310
311
return FAILURE ;
311
312
}
312
313
313
314
intern -> u .file .context = php_stream_context_from_zval (intern -> u .file .zcontext , 0 );
314
- intern -> u .file .stream = php_stream_open_wrapper_ex (ZSTR_VAL (intern -> file_name ), intern -> u .file .open_mode , (use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS , NULL , intern -> u .file .context );
315
+ intern -> u .file .stream = php_stream_open_wrapper_ex (ZSTR_VAL (intern -> file_name ), ZSTR_VAL ( intern -> u .file .open_mode ) , (use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS , NULL , intern -> u .file .context );
315
316
316
317
if (!ZSTR_LEN (intern -> file_name ) || !intern -> u .file .stream ) {
317
318
if (!EG (exception )) {
318
319
zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Cannot open file '%s'" , ZSTR_VAL (intern -> file_name ));
319
320
}
320
- intern -> file_name = NULL ; /* until here it is not a copy */
321
+ zend_string_release ( intern -> u . file . open_mode );
321
322
intern -> u .file .open_mode = NULL ;
323
+ intern -> file_name = NULL ; /* until here it is not a copy */
322
324
return FAILURE ;
323
325
}
324
326
@@ -337,8 +339,6 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
337
339
338
340
intern -> orig_path = zend_string_init (intern -> u .file .stream -> orig_path , strlen (intern -> u .file .stream -> orig_path ), 0 );
339
341
340
- intern -> u .file .open_mode = estrndup (intern -> u .file .open_mode , intern -> u .file .open_mode_len );
341
-
342
342
/* avoid reference counting in debug mode, thus do it manually */
343
343
ZVAL_RES (& intern -> u .file .zresource , intern -> u .file .stream -> res );
344
344
/*!!! TODO: maybe bug?
@@ -519,12 +519,11 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
519
519
{
520
520
ce = ce ? ce : source -> file_class ;
521
521
522
- char * open_mode = "r" ;
523
- size_t open_mode_len = 1 ;
522
+ zend_string * open_mode = ZSTR_CHAR ('r' );
524
523
zval * resource = NULL ;
525
524
526
- if (zend_parse_parameters (num_args , "|sbr !" ,
527
- & open_mode , & open_mode_len , & use_include_path , & resource ) == FAILURE
525
+ if (zend_parse_parameters (num_args , "|Sbr !" ,
526
+ & open_mode , & use_include_path , & resource ) == FAILURE
528
527
) {
529
528
return NULL ;
530
529
}
@@ -538,7 +537,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
538
537
539
538
if (ce -> constructor -> common .scope != spl_ce_SplFileObject ) {
540
539
ZVAL_STR_COPY (& arg1 , source -> file_name );
541
- ZVAL_STRINGL (& arg2 , open_mode , open_mode_len );
540
+ ZVAL_STR_COPY (& arg2 , open_mode );
542
541
zend_call_method_with_2_params (Z_OBJ_P (return_value ), ce , & ce -> constructor , "__construct" , NULL , & arg1 , & arg2 );
543
542
zval_ptr_dtor (& arg1 );
544
543
zval_ptr_dtor (& arg2 );
@@ -554,8 +553,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
554
553
intern -> path = zend_string_init (path , path_len , 0 );
555
554
}
556
555
557
- intern -> u .file .open_mode = open_mode ;
558
- intern -> u .file .open_mode_len = open_mode_len ;
556
+ intern -> u .file .open_mode = zend_string_copy (open_mode );
559
557
intern -> u .file .zcontext = resource ;
560
558
561
559
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
@@ -658,7 +656,7 @@ static inline HashTable *spl_filesystem_object_get_debug_info(zend_object *objec
658
656
}
659
657
if (intern -> type == SPL_FS_FILE ) {
660
658
pnstr = spl_gen_private_prop_name (spl_ce_SplFileObject , "openMode" , sizeof ("openMode" )- 1 );
661
- ZVAL_STRINGL (& tmp , intern -> u .file .open_mode , intern -> u . file . open_mode_len );
659
+ ZVAL_STR_COPY (& tmp , intern -> u .file .open_mode );
662
660
zend_symtable_update (rv , pnstr , & tmp );
663
661
zend_string_release_ex (pnstr , 0 );
664
662
stmp [1 ] = '\0' ;
@@ -2048,29 +2046,24 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
2048
2046
PHP_METHOD (SplFileObject , __construct )
2049
2047
{
2050
2048
spl_filesystem_object * intern = Z_SPLFILESYSTEM_P (ZEND_THIS );
2049
+ zend_string * open_mode = ZSTR_CHAR ('r' );
2051
2050
bool use_include_path = 0 ;
2052
2051
size_t path_len ;
2053
2052
zend_error_handling error_handling ;
2054
2053
2055
- intern -> u .file .open_mode = NULL ;
2056
- intern -> u .file .open_mode_len = 0 ;
2054
+ intern -> u .file .open_mode = ZSTR_CHAR ('r' );
2057
2055
2058
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|sbr!" ,
2059
- & intern -> file_name ,
2060
- & intern -> u .file .open_mode , & intern -> u .file .open_mode_len ,
2056
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "P|Sbr!" ,
2057
+ & intern -> file_name , & open_mode ,
2061
2058
& use_include_path , & intern -> u .file .zcontext ) == FAILURE ) {
2062
2059
intern -> u .file .open_mode = NULL ;
2063
2060
intern -> file_name = NULL ;
2064
2061
RETURN_THROWS ();
2065
2062
}
2066
2063
2067
- if (intern -> u .file .open_mode == NULL ) {
2068
- intern -> u .file .open_mode = "r" ;
2069
- intern -> u .file .open_mode_len = 1 ;
2070
- }
2071
-
2072
2064
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
2073
2065
2066
+ intern -> u .file .open_mode = zend_string_copy (open_mode );
2074
2067
if (spl_filesystem_file_open (intern , use_include_path , 0 ) == SUCCESS ) {
2075
2068
path_len = strlen (intern -> u .file .stream -> orig_path );
2076
2069
@@ -2113,8 +2106,7 @@ PHP_METHOD(SplTempFileObject, __construct)
2113
2106
file_name = zend_string_init ("php://temp" , sizeof ("php://temp" )- 1 , 0 );
2114
2107
}
2115
2108
intern -> file_name = file_name ;
2116
- intern -> u .file .open_mode = "wb" ;
2117
- intern -> u .file .open_mode_len = sizeof ("wb" )- 1 ;
2109
+ intern -> u .file .open_mode = zend_string_init ("wb" , sizeof ("wb" )- 1 , 0 );
2118
2110
2119
2111
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
2120
2112
if (spl_filesystem_file_open (intern , 0 , 0 ) == SUCCESS ) {
0 commit comments