$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 = '';