Safety : flush/close file before calling zlib_deflate on it

This commit is contained in:
Aaron Culliney 2015-10-17 12:02:21 -07:00
parent 1d5c20cc5f
commit 053a4c8c93

View File

@ -755,6 +755,9 @@ const char *disk6_eject(int drive) {
disk6.disk[drive].nibblized = 0; disk6.disk[drive].nibblized = 0;
if (disk6.disk[drive].fp) { 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 // foo.dsk -> foo.dsk.gz
err = zlib_deflate(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE); err = zlib_deflate(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE);
if (err) { if (err) {
@ -764,10 +767,7 @@ const char *disk6_eject(int drive) {
} }
FREE(disk6.disk[drive].file_name); FREE(disk6.disk[drive].file_name);
TEMP_FAILURE_RETRY(fflush(disk6.disk[drive].fp)); memset(&disk6.disk[drive], 0x0, sizeof(disk6.disk[drive]));
TEMP_FAILURE_RETRY(fclose(disk6.disk[drive].fp));
disk6.disk[drive].fp = NULL;
disk6.disk[drive].track_width = 0;
} }
return err; return err;