From 053a4c8c93cc2a2003cd8c27ac7ced8ee1933629 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 17 Oct 2015 12:02:21 -0700 Subject: [PATCH] Safety : flush/close file before calling zlib_deflate on it --- src/disk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/disk.c b/src/disk.c index 46a15788..03b6e7b1 100644 --- a/src/disk.c +++ b/src/disk.c @@ -755,6 +755,9 @@ const char *disk6_eject(int drive) { disk6.disk[drive].nibblized = 0; if (disk6.disk[drive].fp) { + TEMP_FAILURE_RETRY(fflush(disk6.disk[drive].fp)); + TEMP_FAILURE_RETRY(fclose(disk6.disk[drive].fp)); + // foo.dsk -> foo.dsk.gz err = zlib_deflate(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE); if (err) { @@ -764,10 +767,7 @@ const char *disk6_eject(int drive) { } FREE(disk6.disk[drive].file_name); - TEMP_FAILURE_RETRY(fflush(disk6.disk[drive].fp)); - TEMP_FAILURE_RETRY(fclose(disk6.disk[drive].fp)); - disk6.disk[drive].fp = NULL; - disk6.disk[drive].track_width = 0; + memset(&disk6.disk[drive], 0x0, sizeof(disk6.disk[drive])); } return err;