@@ -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 "Failed to open stream: 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,18 +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- php_stream_tidy_wrapper_name_error_log (wrapper_name );
2177- pefree (wrapper_name , persistent );
2178- if (resolved_path ) {
2179- zend_string_release_ex (resolved_path , 0 );
2180- }
2181- return NULL ;
2150+ stream = NULL ;
2151+ goto cleanup ;
21822152 }
21832153
21842154 stream -> wrapper = wrapper ;
@@ -2211,36 +2181,20 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
22112181 (options & STREAM_WILL_CAST )
22122182 ? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE )) {
22132183 case PHP_STREAM_UNCHANGED :
2214- if (resolved_path ) {
2215- zend_string_release_ex (resolved_path , 0 );
2216- }
2217- pefree (wrapper_name , persistent );
2218- return stream ;
2184+ goto cleanup ;
22192185 case PHP_STREAM_RELEASED :
22202186 if (newstream -> orig_path ) {
22212187 pefree (newstream -> orig_path , persistent );
22222188 }
22232189 newstream -> orig_path = pestrdup (path , persistent );
2224- if (resolved_path ) {
2225- zend_string_release_ex (resolved_path , 0 );
2226- }
2227- pefree (wrapper_name , persistent );
2228- return newstream ;
2190+ stream = newstream ;
2191+ goto cleanup ;
22292192 default :
2230- php_stream_close (stream );
22312193 php_stream_wrapper_warn (wrapper , context , options , SeekNotSupported ,
22322194 "Failed to open stream: could not make seekable - %s" , path );
2233- if (options & REPORT_ERRORS ) {
2234- if (opened_path && * opened_path ) {
2235- zend_string_release_ex (* opened_path , 0 );
2236- * opened_path = NULL ;
2237- }
2238- }
2239- pefree (wrapper_name , persistent );
2240- if (resolved_path ) {
2241- zend_string_release_ex (resolved_path , 0 );
2242- }
2243- return NULL ;
2195+ php_stream_close (stream );
2196+ stream = NULL ;
2197+ goto cleanup ;
22442198 }
22452199 }
22462200
@@ -2253,10 +2207,18 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
22532207 }
22542208 }
22552209
2210+ cleanup :
22562211 pefree (wrapper_name , persistent );
2212+ cleanup_no_wrapper_name :
22572213 if (resolved_path ) {
22582214 zend_string_release_ex (resolved_path , 0 );
22592215 }
2216+ if (stream == NULL ) {
2217+ if (opened_path && * opened_path ) {
2218+ zend_string_release_ex (* opened_path , 0 );
2219+ * opened_path = NULL ;
2220+ }
2221+ }
22602222 return stream ;
22612223}
22622224/* }}} */
0 commit comments