From fc87f96e07fd75d887bf370ca8c8c649f96d1896 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sun, 6 Dec 2015 17:06:53 +0000 Subject: [PATCH] Upgrader: FTP: Cleanup temporary files during FTP download failures. Props ruud@joyo Fixes #34772 git-svn-id: https://develop.svn.wordpress.org/trunk@35777 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-filesystem-ftpext.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index 38536a0ea9..bba4608a8c 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -116,12 +116,17 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $tempfile = wp_tempnam($file); $temp = fopen($tempfile, 'w+'); - if ( ! $temp ) + if ( ! $temp ) { + unlink( $tempfile ); return false; - - if ( ! @ftp_fget($this->link, $temp, $file, FTP_BINARY ) ) + } + + 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 = '';