@@ -2101,10 +2101,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
21012101 options &= ~USE_PATH ;
21022102 }
21032103 if (EG (exception )) {
2104- if (resolved_path ) {
2105- zend_string_release_ex (resolved_path , false);
2106- }
2107- return NULL ;
2104+ goto cleanup_no_wrapper_name ;
21082105 }
21092106 }
21102107
@@ -2114,28 +2111,19 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
21142111 if (UNEXPECTED (!wrapper )) {
21152112 php_stream_wrapper_warn_name (PHP_STREAM_ERROR_WRAPPER_DEFAULT_NAME , context , options , OpenFailed ,
21162113 "Failed to open stream: no suitable wrapper could be found" );
2117- if (resolved_path ) {
2118- zend_string_release_ex (resolved_path , 0 );
2119- }
2120- return NULL ;
2114+ goto cleanup_no_wrapper_name ;
21212115 }
21222116 if ((options & STREAM_USE_URL ) && !wrapper -> is_url ) {
21232117 php_stream_wrapper_warn (wrapper , context , options ,
21242118 ProtocolUnsupported ,
21252119 "This function may only be used against URLs" );
2126- if (resolved_path ) {
2127- zend_string_release_ex (resolved_path , 0 );
2128- }
2129- return NULL ;
2120+ goto cleanup_no_wrapper_name ;
21302121 }
21312122
21322123 if (!wrapper -> wops -> stream_opener ) {
21332124 php_stream_wrapper_warn (wrapper , context , options , NoOpener ,
21342125 "Failed to open stream: wrapper does not support stream open" );
2135- if (resolved_path ) {
2136- zend_string_release_ex (resolved_path , 0 );
2137- }
2138- return NULL ;
2126+ goto cleanup_no_wrapper_name ;
21392127 }
21402128
21412129 /* wrapper name needs to be stored as wrapper can be removed in opener (user stream) */
@@ -2148,17 +2136,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
21482136 if (options & REPORT_ERRORS ) {
21492137 php_stream_display_wrapper_name_errors (wrapper_name , context , PHP_STREAM_EC (OpenFailed ),
21502138 "Failed to open stream" );
2151- if (opened_path && * opened_path ) {
2152- zend_string_release_ex (* opened_path , 0 );
2153- * opened_path = NULL ;
2154- }
21552139 }
21562140 php_stream_tidy_wrapper_name_error_log (wrapper_name );
2157- pefree (wrapper_name , persistent );
2158- if (resolved_path ) {
2159- zend_string_release_ex (resolved_path , 0 );
2160- }
2161- return NULL ;
2141+ goto cleanup ;
21622142 }
21632143
21642144 /* if the caller asked for a persistent stream but the wrapper did not
@@ -2167,17 +2147,8 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
21672147 php_stream_wrapper_warn (wrapper , context , options , PersistentNotSupported ,
21682148 "Failed to open stream: wrapper does not support persistent streams" );
21692149 php_stream_close (stream );
2170- if (options & REPORT_ERRORS ) {
2171- if (opened_path && * opened_path ) {
2172- zend_string_release_ex (* opened_path , 0 );
2173- * opened_path = NULL ;
2174- }
2175- }
2176- pefree (wrapper_name , persistent );
2177- if (resolved_path ) {
2178- zend_string_release_ex (resolved_path , 0 );
2179- }
2180- return NULL ;
2150+ stream = NULL ;
2151+ goto cleanup ;
21812152 }
21822153
21832154 stream -> wrapper = wrapper ;
@@ -2210,31 +2181,21 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
22102181 (options & STREAM_WILL_CAST )
22112182 ? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE )) {
22122183 case PHP_STREAM_UNCHANGED :
2213- if (resolved_path ) {
2214- zend_string_release_ex (resolved_path , 0 );
2215- }
2216- pefree (wrapper_name , persistent );
2217- return stream ;
2184+ goto cleanup ;
22182185 case PHP_STREAM_RELEASED :
22192186 if (newstream -> orig_path ) {
22202187 pefree (newstream -> orig_path , persistent );
22212188 }
22222189 newstream -> orig_path = pestrdup (path , persistent );
2223- if (resolved_path ) {
2224- zend_string_release_ex (resolved_path , 0 );
2225- }
2226- pefree (wrapper_name , persistent );
2227- return newstream ;
2190+ stream = newstream ;
2191+ goto cleanup ;
22282192 default :
2229- php_stream_close (stream );
22302193 php_stream_wrapper_warn (wrapper , context , options ,
22312194 SeekNotSupported ,
22322195 "could not make seekable - %s" , path );
2233- pefree (wrapper_name , persistent );
2234- if (resolved_path ) {
2235- zend_string_release_ex (resolved_path , 0 );
2236- }
2237- return NULL ;
2196+ php_stream_close (stream );
2197+ stream = NULL ;
2198+ goto cleanup ;
22382199 }
22392200 }
22402201
@@ -2247,10 +2208,18 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
22472208 }
22482209 }
22492210
2211+ cleanup :
22502212 pefree (wrapper_name , persistent );
2213+ cleanup_no_wrapper_name :
22512214 if (resolved_path ) {
22522215 zend_string_release_ex (resolved_path , 0 );
22532216 }
2217+ if (stream == NULL ) {
2218+ if (opened_path && * opened_path ) {
2219+ zend_string_release_ex (* opened_path , 0 );
2220+ * opened_path = NULL ;
2221+ }
2222+ }
22542223 return stream ;
22552224}
22562225/* }}} */
0 commit comments