diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index e1202aedd2..f337c733c8 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -120,13 +120,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { unlink( $tempfile ); return false; } - + if ( ! @ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) { fclose( $temp ); unlink( $tempfile ); return false; } - + fseek( $temp, 0 ); // Skip back to the start of the file being written to $contents = ''; @@ -159,8 +159,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { public function put_contents($file, $contents, $mode = false ) { $tempfile = wp_tempnam($file); $temp = fopen( $tempfile, 'wb+' ); - if ( ! $temp ) + + if ( ! $temp ) { + unlink( $tempfile ); return false; + } mbstring_binary_safe_encoding(); diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php index fe74d33c1d..ff0b882414 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -121,8 +121,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { $temp = wp_tempnam( $file ); - if ( ! $temphandle = fopen($temp, 'w+') ) + if ( ! $temphandle = fopen( $temp, 'w+' ) ) { + unlink( $temp ); return false; + } mbstring_binary_safe_encoding();