Memory fix for struct ImageInfo (PR #715)

ImageInfo is not a POD and cannot simply be initialised with ZeroMemory()
. the std::string constructor must be called.
. ImageInfo: simplify code using new / delete vs VirtualAlloc
Also fixed mismatching new / delete [] reported by valgrind
This commit is contained in:
Andrea
2019-11-11 14:09:29 +00:00
committed by TomCh
parent 20b8515b7b
commit d6d76ae6bc
3 changed files with 25 additions and 7 deletions
+2 -5
View File
@@ -53,11 +53,8 @@ ImageError_e ImageOpen( const std::string & pszImageFilename,
return eIMAGE_ERROR_BAD_POINTER;
// CREATE A RECORD FOR THE FILE
*ppImageInfo = (ImageInfo*) VirtualAlloc(NULL, sizeof(ImageInfo), MEM_COMMIT, PAGE_READWRITE);
if (*ppImageInfo == NULL)
return eIMAGE_ERROR_BAD_POINTER;
*ppImageInfo = new ImageInfo();
ZeroMemory(*ppImageInfo, sizeof(ImageInfo));
ImageInfo* pImageInfo = *ppImageInfo;
pImageInfo->bWriteProtected = *pWriteProtected;
if (bExpectFloppy) pImageInfo->pImageHelper = &sg_DiskImageHelper;
@@ -116,7 +113,7 @@ void ImageClose(ImageInfo* const pImageInfo, const bool bOpenError /*=false*/)
pImageInfo->pImageHelper->Close(pImageInfo, bDeleteFile);
VirtualFree(pImageInfo, 0, MEM_RELEASE);
delete pImageInfo;
}
//===========================================================================