@@ -38,8 +38,6 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
3838 }
3939
4040 if (!IS_ABSOLUTE_PATH (filename , filename_len ) && !strstr (filename , "://" )) {
41- char * arch ;
42- size_t arch_len ;
4341 zend_string * fname = zend_get_executed_filename_ex ();
4442
4543 /* we are checking for existence of a file within the relative path. Chances are good that this is
@@ -48,7 +46,8 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
4846 goto skip_phar ;
4947 }
5048
51- if (SUCCESS == phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), & arch , & arch_len , NULL , 2 , 0 )) {
49+ zend_string * arch = phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), NULL , 2 , 0 );
50+ if (arch ) {
5251 php_stream_context * context = NULL ;
5352 php_stream * stream ;
5453 char * name ;
@@ -58,12 +57,12 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
5857 zend_string * entry = phar_fix_filepath (filename , filename_len , true);
5958
6059 if (ZSTR_VAL (entry )[0 ] == '/' ) {
61- spprintf (& name , 4096 , "phar://%s%s" , arch , ZSTR_VAL (entry ));
60+ spprintf (& name , 4096 , "phar://%s%s" , ZSTR_VAL ( arch ) , ZSTR_VAL (entry ));
6261 } else {
63- spprintf (& name , 4096 , "phar://%s/%s" , arch , ZSTR_VAL (entry ));
62+ spprintf (& name , 4096 , "phar://%s/%s" , ZSTR_VAL ( arch ) , ZSTR_VAL (entry ));
6463 }
6564 zend_string_release_ex (entry , false);
66- efree (arch );
65+ zend_string_release_ex (arch , false );
6766 if (zcontext ) {
6867 context = php_stream_context_from_zval (zcontext , 0 );
6968 }
@@ -84,8 +83,6 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
8483
8584static zend_string * phar_get_name_for_relative_paths (zend_string * filename , bool using_include_path )
8685{
87- char * arch ;
88- size_t arch_len ;
8986 zend_string * fname = zend_get_executed_filename_ex ();
9087
9188 /* we are checking for existence of a file within the relative path. Chances are good that this is
@@ -94,7 +91,8 @@ static zend_string* phar_get_name_for_relative_paths(zend_string *filename, bool
9491 return NULL ;
9592 }
9693
97- if (FAILURE == phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), & arch , & arch_len , NULL , 2 , 0 )) {
94+ zend_string * arch = phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), NULL , 2 , 0 );
95+ if (!arch ) {
9896 return NULL ;
9997 }
10098
@@ -110,7 +108,7 @@ static zend_string* phar_get_name_for_relative_paths(zend_string *filename, bool
110108 if (using_include_path ) {
111109 if (!(name = phar_find_in_include_path (filename , NULL ))) {
112110 /* this file is not in the phar, use the original path */
113- efree (arch );
111+ zend_string_release_ex (arch , false );
114112 return NULL ;
115113 }
116114 } else {
@@ -124,24 +122,24 @@ static zend_string* phar_get_name_for_relative_paths(zend_string *filename, bool
124122 /* this file is not in the phar, use the original path */
125123 if (!is_in_phar ) {
126124 zend_string_release_ex (entry , false);
127- efree (arch );
125+ zend_string_release_ex (arch , false );
128126 return NULL ;
129127 }
130128 /* auto-convert to phar:// */
131129 if (ZSTR_VAL (entry )[0 ] == '/' ) {
132- ZEND_ASSERT (strlen ("phar://" ) + arch_len + ZSTR_LEN (entry ) < 4096 );
130+ ZEND_ASSERT (strlen ("phar://" ) + ZSTR_LEN ( arch ) + ZSTR_LEN (entry ) < 4096 );
133131 name = zend_string_concat3 (
134132 "phar://" , strlen ("phar://" ),
135- arch , arch_len ,
133+ ZSTR_VAL ( arch ), ZSTR_LEN ( arch ) ,
136134 ZSTR_VAL (entry ), ZSTR_LEN (entry )
137135 );
138136 } else {
139- name = strpprintf (4096 , "phar://%s/%s" , arch , ZSTR_VAL (entry ));
137+ name = strpprintf (4096 , "phar://%s/%s" , ZSTR_VAL ( arch ) , ZSTR_VAL (entry ));
140138 }
141139 zend_string_release_ex (entry , false);
142140 }
143141
144- efree (arch );
142+ zend_string_release_ex (arch , false );
145143 return name ;
146144}
147145
@@ -492,9 +490,9 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ
492490 phar = PHAR_G (last_phar );
493491 goto splitted ;
494492 }
495- char * arch ;
496- size_t arch_len ;
497- if (SUCCESS == phar_split_fname ( ZSTR_VAL ( fname ), ZSTR_LEN ( fname ), & arch , & arch_len , NULL , 2 , 0 ) ) {
493+
494+ zend_string * arch = phar_split_fname ( ZSTR_VAL ( fname ), ZSTR_LEN ( fname ), NULL , 2 , 0 ) ;
495+ if (arch ) {
498496 /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
499497 zend_result has_archive = phar_get_archive (& phar , arch , arch_len , NULL , NULL );
500498 efree (arch );
@@ -721,8 +719,6 @@ PHP_FUNCTION(phar_is_file) /* {{{ */
721719 goto skip_phar ;
722720 }
723721 if (!IS_ABSOLUTE_PATH (filename , filename_len ) && !strstr (filename , "://" )) {
724- char * arch ;
725- size_t arch_len ;
726722 zend_string * fname = zend_get_executed_filename_ex ();
727723
728724 /* we are checking for existence of a file within the relative path. Chances are good that this is
@@ -731,7 +727,8 @@ PHP_FUNCTION(phar_is_file) /* {{{ */
731727 goto skip_phar ;
732728 }
733729
734- if (SUCCESS == phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), & arch , & arch_len , NULL , 2 , 0 )) {
730+ zend_string * arch = phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), NULL , 2 , 0 );
731+ if (arch ) {
735732 phar_archive_data * phar ;
736733
737734 /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
@@ -747,12 +744,10 @@ PHP_FUNCTION(phar_is_file) /* {{{ */
747744 }
748745 zend_string_release_ex (entry , false);
749746 if (etemp ) {
750- efree (arch );
751747 RETURN_BOOL (!etemp -> is_dir );
752748 }
753749 /* this file is not in the current directory, use the original path */
754750 }
755- efree (arch );
756751 RETURN_FALSE ;
757752 }
758753 }
@@ -779,8 +774,6 @@ PHP_FUNCTION(phar_is_link) /* {{{ */
779774 goto skip_phar ;
780775 }
781776 if (!IS_ABSOLUTE_PATH (filename , filename_len ) && !strstr (filename , "://" )) {
782- char * arch ;
783- size_t arch_len ;
784777 zend_string * fname = zend_get_executed_filename_ex ();
785778
786779 /* we are checking for existence of a file within the relative path. Chances are good that this is
@@ -789,7 +782,8 @@ PHP_FUNCTION(phar_is_link) /* {{{ */
789782 goto skip_phar ;
790783 }
791784
792- if (SUCCESS == phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), & arch , & arch_len , NULL , 2 , 0 )) {
785+ zend_string * arch = phar_split_fname (ZSTR_VAL (fname ), ZSTR_LEN (fname ), NULL , 2 , 0 );
786+ if (arch ) {
793787 phar_archive_data * phar ;
794788
795789 /* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
@@ -805,11 +799,9 @@ PHP_FUNCTION(phar_is_link) /* {{{ */
805799 }
806800 zend_string_release_ex (entry , false);
807801 if (etemp ) {
808- efree (arch );
809802 RETURN_BOOL (etemp -> link );
810803 }
811804 }
812- efree (arch );
813805 RETURN_FALSE ;
814806 }
815807 }
0 commit comments