From: Toni Wilen Date: Sun, 27 Jan 2019 08:41:11 +0000 (+0200) Subject: Disk image handle was not freed in some error situations. Write protection could... X-Git-Tag: 4200~67 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=10b9916a47eb335e56dd331869b14046b096e387;p=francis%2Fwinuae.git Disk image handle was not freed in some error situations. Write protection could have remained active after disk change in rare situations when change was done using UAE interface, not GUI. --- diff --git a/disk.cpp b/disk.cpp index b1ae8a4c..b6f38aec 100644 --- a/disk.cpp +++ b/disk.cpp @@ -1000,16 +1000,20 @@ static int iswritefileempty (struct uae_prefs *p, const TCHAR *name) int tracks, ddhd, i, ret; zf = getexistingwritefile (p, name, &wrprot); - if (!zf) return 1; + if (!zf) + return 1; zfile_fread (buffer, sizeof (char), 8, zf); - if (strncmp ((uae_char*)buffer, "UAE-1ADF", 8)) + if (strncmp((uae_char*)buffer, "UAE-1ADF", 8)) { + zfile_fclose(zf); return 0; + } ret = read_header_ext2 (zf, td, &tracks, &ddhd); zfile_fclose (zf); if (!ret) return 1; for (i = 0; i < tracks; i++) { - if (td[i].bitlen) return 0; + if (td[i].bitlen) + return 0; } return 1; } @@ -1142,7 +1146,7 @@ static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR drv->dskready_down_time = 0; } - if (drv->diskfile == 0 && !drv->catweasel) { + if (drv->diskfile == NULL && !drv->catweasel) { track_reset (drv); return 0; } @@ -2438,6 +2442,7 @@ static bool convert_adf_to_ext2 (drive *drv, int mode) zfile_fclose (tmp); return false; } + zfile_fclose(tmp); } else { return false; } @@ -2525,7 +2530,6 @@ static void drive_eject (drive * drv) #endif if (drv->diskfile || drv->filetype >= 0) statusline_add_message(STATUSTYPE_FLOPPY, _T("DF%d: -"), drv - floppy); - gui_disk_image_change(drv - floppy, NULL, drv->wrprot); drive_image_free (drv); drv->dskeject = false; drv->dskchange = true; @@ -2534,10 +2538,12 @@ static void drive_eject (drive * drv) drv->dskready = 0; drv->dskready_up_time = 0; drv->dskready_down_time = 0; + drv->forcedwrprot = false; drv->crc32 = 0; drive_settype_id (drv); /* Back to 35 DD */ if (disk_debug_logging > 0) write_log (_T("eject drive %ld\n"), drv - &floppy[0]); + gui_disk_image_change(drv - floppy, NULL, drv->wrprot); inprec_recorddiskchange (drv - floppy, NULL, false); } @@ -2749,15 +2755,17 @@ int disk_setwriteprotect (struct uae_prefs *p, int num, const TCHAR *fname_in, b write_log(_T("old = %d writeprot = %d master = %d\n"), oldprotect, wrprot1, p->floppy_read_only); - if (wrprot1 && p->floppy_read_only) + if (wrprot1 && p->floppy_read_only) { + zfile_fclose(zf1); return 0; + } if (zfile_iscompressed (zf1)) wrprot1 = 1; zfile_fclose (zf1); zf2 = getexistingwritefile(p, fname_in, &wrprot2); name2 = DISK_get_saveimagepath(fname_in, -2); - if (needwritefile && zf2 == 0) + if (needwritefile && zf2 == NULL) disk_creatediskfile (p, name2, 1, drvtype, -1, NULL, false, false, NULL); zfile_fclose (zf2); if (writeprotected && iswritefileempty (p, fname_in)) { @@ -2771,6 +2779,10 @@ int disk_setwriteprotect (struct uae_prefs *p, int num, const TCHAR *fname_in, b if (!needwritefile) diskfile_readonly (outfname, writeprotected); diskfile_readonly (name2, writeprotected); + + floppy[num].forcedwrprot = false; + floppy[num].newnamewriteprotected = false; + return 1; }