Fix some problems reported by valgrind:
1) HDD is not a POD and so ZeroMemory does not replace a constructor 2) mismatch free / delete [] 3) no need to a shared_ptr<BYTES>, new, just use a vector Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
bcf57a4e19
commit
7c4f50c4fa
3 changed files with 40 additions and 9 deletions
|
@ -124,7 +124,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
void clear()
|
||||
{
|
||||
ZeroMemory(imagename, sizeof(imagename));
|
||||
ZeroMemory(fullname, sizeof(imagename));
|
||||
ZeroMemory(fullname, sizeof(fullname));
|
||||
strFilenameInZip.clear();
|
||||
imagehandle = NULL;
|
||||
bWriteProtected = false;
|
||||
|
@ -1364,11 +1364,10 @@ static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit)
|
|||
g_aFloppyDisk[unit].trackimagedata = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK_IMAGE_DATA);
|
||||
g_aFloppyDisk[unit].trackimagedirty = yamlLoadHelper.LoadUint(SS_YAML_KEY_TRACK_IMAGE_DIRTY);
|
||||
|
||||
std::shared_ptr<BYTE> pTrack( new BYTE [NIBBLES_PER_TRACK] );
|
||||
memset(pTrack.get(), 0, NIBBLES_PER_TRACK);
|
||||
std::vector<BYTE> pTrack(NIBBLES_PER_TRACK);
|
||||
if (yamlLoadHelper.GetSubMap(SS_YAML_KEY_TRACK_IMAGE))
|
||||
{
|
||||
yamlLoadHelper.LoadMemory(pTrack.get(), NIBBLES_PER_TRACK);
|
||||
yamlLoadHelper.LoadMemory(pTrack.data(), NIBBLES_PER_TRACK);
|
||||
yamlLoadHelper.PopMap();
|
||||
}
|
||||
|
||||
|
@ -1384,7 +1383,7 @@ static void DiskLoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, UINT unit)
|
|||
if (g_aFloppyDisk[unit].trackimage == NULL)
|
||||
bImageError = true;
|
||||
else
|
||||
memcpy(g_aFloppyDisk[unit].trackimage, pTrack.get(), NIBBLES_PER_TRACK);
|
||||
memcpy(g_aFloppyDisk[unit].trackimage, pTrack.data(), NIBBLES_PER_TRACK);
|
||||
}
|
||||
|
||||
if (bImageError)
|
||||
|
|
|
@ -114,6 +114,38 @@ Overview
|
|||
|
||||
struct HDD
|
||||
{
|
||||
HDD()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
~HDD()
|
||||
{
|
||||
if (imagehandle)
|
||||
ImageClose(imagehandle);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
// This is not a POD (there is a std::string)
|
||||
// ZeroMemory does not work
|
||||
ZeroMemory(imagename, sizeof(imagename));
|
||||
ZeroMemory(fullname, sizeof(fullname));
|
||||
strFilenameInZip.clear();
|
||||
imagehandle = NULL;
|
||||
bWriteProtected = false;
|
||||
hd_error = 0;
|
||||
hd_memblock = 0;
|
||||
hd_diskblock = 0;
|
||||
hd_buf_ptr = 0;
|
||||
hd_imageloaded = 0;
|
||||
ZeroMemory(hd_buf, sizeof(hd_buf));
|
||||
#if HD_LED
|
||||
hd_status_next = Disk_Status_e(0);
|
||||
hd_status_prev = Disk_Status_e(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// From Disk_t
|
||||
TCHAR imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension) [not used]
|
||||
TCHAR fullname[ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip>
|
||||
|
@ -143,7 +175,7 @@ static BYTE g_nHD_UnitNum = HARDDISK_1<<7; // b7=unit
|
|||
// . ProDOS will write to Command before switching drives
|
||||
static BYTE g_nHD_Command;
|
||||
|
||||
static HDD g_HardDisk[NUM_HARDDISKS] = {0};
|
||||
static std::vector<HDD> g_HardDisk(NUM_HARDDISKS);
|
||||
|
||||
static bool g_bSaveDiskImage = true; // Save the DiskImage name to Registry
|
||||
static UINT g_uSlot = 7;
|
||||
|
@ -797,7 +829,7 @@ bool HD_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version, co
|
|||
for (UINT i=0; i<NUM_HARDDISKS; i++)
|
||||
{
|
||||
HD_Unplug(i);
|
||||
ZeroMemory(&g_HardDisk[i], sizeof(HDD));
|
||||
g_HardDisk[i].clear();
|
||||
}
|
||||
|
||||
bool bResSelectImage1 = HD_LoadSnapshotHDDUnit(yamlLoadHelper, HARDDISK_1);
|
||||
|
|
|
@ -154,7 +154,7 @@ int YamlHelper::ParseMap(MapYaml& mapYaml)
|
|||
mapValue.value = pValue;
|
||||
mapValue.subMap = NULL;
|
||||
mapYaml[std::string(pKey)] = mapValue;
|
||||
delete [] pKey; pKey = NULL;
|
||||
free(pKey); pKey = NULL;
|
||||
}
|
||||
|
||||
bKey = bKey ? false : true;
|
||||
|
@ -166,7 +166,7 @@ int YamlHelper::ParseMap(MapYaml& mapYaml)
|
|||
}
|
||||
|
||||
if (pKey)
|
||||
delete [] pKey;
|
||||
free(pKey);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue