- fclose( $this->stream_handle );
- return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
+ if ( $r['stream'] ) {
+ curl_close( $handle );
+ fclose( $this->stream_handle );
+ return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
+ } else {
+ curl_close( $handle );
+ return new WP_Error( 'http_request_failed', curl_error( $handle ) );
+ }