From 4786de0cc7ce3d0e462d87a15e02d695dade40d1 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 17 Aug 2024 16:14:09 +0100 Subject: [PATCH] Floppy/Harddisk images: on failure, close handle for all return paths. (Fixes #1227) --- source/DiskImage.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/DiskImage.cpp b/source/DiskImage.cpp index 7851f53b..ff0c1c84 100644 --- a/source/DiskImage.cpp +++ b/source/DiskImage.cpp @@ -68,18 +68,23 @@ ImageError_e ImageOpen( const std::string & pszImageFilename, if (pImageInfo->pImageType && pImageInfo->pImageType->GetType() == eImageHDV) { if (bExpectFloppy) + { + ImageClose(*ppImageInfo); + *ppImageInfo = NULL; Err = eIMAGE_ERROR_UNSUPPORTED_HDV; + } return Err; } // THE FILE MATCHES A KNOWN FORMAT _ASSERT(bExpectFloppy); - if (!bExpectFloppy) - return eIMAGE_ERROR_UNSUPPORTED; - - if (!pImageInfo->uNumTracks) + if (!bExpectFloppy || !pImageInfo->uNumTracks) + { + ImageClose(*ppImageInfo); + *ppImageInfo = NULL; return eIMAGE_ERROR_UNSUPPORTED; + } *pWriteProtected = pImageInfo->bWriteProtected;