Filesystem API: Cleanup temporary file when the temporary file couldn't be opened.

Props ruud@joyo.
See #34772.
Fixes #36942, #36943.

git-svn-id: https://develop.svn.wordpress.org/trunk@38094 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling 2016-07-18 19:42:48 +00:00
parent b55afe7f4d
commit ff6d8819e4
2 changed files with 9 additions and 4 deletions

View File

@ -120,13 +120,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
unlink( $tempfile ); unlink( $tempfile );
return false; return false;
} }
if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) { if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) {
fclose( $temp ); fclose( $temp );
unlink( $tempfile ); unlink( $tempfile );
return false; return false;
} }
fseek( $temp, 0 ); // Skip back to the start of the file being written to fseek( $temp, 0 ); // Skip back to the start of the file being written to
$contents = ''; $contents = '';
@ -159,8 +159,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
public function put_contents($file, $contents, $mode = false ) { public function put_contents($file, $contents, $mode = false ) {
$tempfile = wp_tempnam($file); $tempfile = wp_tempnam($file);
$temp = fopen( $tempfile, 'wb+' ); $temp = fopen( $tempfile, 'wb+' );
if ( ! $temp )
if ( ! $temp ) {
unlink( $tempfile );
return false; return false;
}
mbstring_binary_safe_encoding(); mbstring_binary_safe_encoding();

View File

@ -121,8 +121,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$temp = wp_tempnam( $file ); $temp = wp_tempnam( $file );
if ( ! $temphandle = fopen($temp, 'w+') ) if ( ! $temphandle = fopen( $temp, 'w+' ) ) {
unlink( $temp );
return false; return false;
}
mbstring_binary_safe_encoding(); mbstring_binary_safe_encoding();