Fix memory leak in CardManager (PR #885)

This commit is contained in:
Andrea 2020-12-06 18:43:18 +00:00 committed by GitHub
parent 59294d9d72
commit 0d741d0b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -120,6 +120,12 @@ void CardManager::RemoveInternal(UINT slot)
m_slot[slot] = NULL;
}
void CardManager::RemoveAuxInternal()
{
delete m_aux;
m_aux = NULL;
}
void CardManager::Remove(UINT slot)
{
RemoveInternal(slot);
@ -131,6 +137,8 @@ void CardManager::InsertAux(SS_CARDTYPE type)
if (type == CT_Empty)
return RemoveAux();
RemoveAuxInternal();
switch (type)
{
case CT_80Col:
@ -146,10 +154,13 @@ void CardManager::InsertAux(SS_CARDTYPE type)
_ASSERT(0);
break;
}
// for consistency m_aux must never be NULL
_ASSERT(m_aux != NULL);
}
void CardManager::RemoveAux(void)
{
delete m_aux;
RemoveAuxInternal();
m_aux = new EmptyCard;
}

View File

@ -24,8 +24,8 @@ public:
~CardManager(void)
{
for (UINT i=0; i<NUM_SLOTS; i++)
Remove(i);
RemoveAux();
RemoveInternal(i);
RemoveAuxInternal();
}
void Insert(UINT slot, SS_CARDTYPE type);
@ -34,7 +34,6 @@ public:
Card& GetRef(UINT slot)
{
SS_CARDTYPE t=QuerySlot(slot); _ASSERT((t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2) && m_slot[slot]);
if (!m_slot[slot]) throw std::runtime_error("slot/card mismatch");
return *m_slot[slot];
}
Card* GetObj(UINT slot) { SS_CARDTYPE t=QuerySlot(slot); _ASSERT(t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2); return m_slot[slot]; }
@ -54,6 +53,7 @@ public:
private:
void RemoveInternal(UINT slot);
void RemoveAuxInternal();
Card* m_slot[NUM_SLOTS];
Card* m_aux;