mirror of
https://github.com/AppleWin/AppleWin.git
synced 2024-06-26 16:29:30 +00:00
Fix memory leak in CardManager (PR #885)
This commit is contained in:
parent
59294d9d72
commit
0d741d0b9f
|
@ -120,6 +120,12 @@ void CardManager::RemoveInternal(UINT slot)
|
||||||
m_slot[slot] = NULL;
|
m_slot[slot] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardManager::RemoveAuxInternal()
|
||||||
|
{
|
||||||
|
delete m_aux;
|
||||||
|
m_aux = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void CardManager::Remove(UINT slot)
|
void CardManager::Remove(UINT slot)
|
||||||
{
|
{
|
||||||
RemoveInternal(slot);
|
RemoveInternal(slot);
|
||||||
|
@ -131,6 +137,8 @@ void CardManager::InsertAux(SS_CARDTYPE type)
|
||||||
if (type == CT_Empty)
|
if (type == CT_Empty)
|
||||||
return RemoveAux();
|
return RemoveAux();
|
||||||
|
|
||||||
|
RemoveAuxInternal();
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CT_80Col:
|
case CT_80Col:
|
||||||
|
@ -146,10 +154,13 @@ void CardManager::InsertAux(SS_CARDTYPE type)
|
||||||
_ASSERT(0);
|
_ASSERT(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for consistency m_aux must never be NULL
|
||||||
|
_ASSERT(m_aux != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardManager::RemoveAux(void)
|
void CardManager::RemoveAux(void)
|
||||||
{
|
{
|
||||||
delete m_aux;
|
RemoveAuxInternal();
|
||||||
m_aux = new EmptyCard;
|
m_aux = new EmptyCard;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ public:
|
||||||
~CardManager(void)
|
~CardManager(void)
|
||||||
{
|
{
|
||||||
for (UINT i=0; i<NUM_SLOTS; i++)
|
for (UINT i=0; i<NUM_SLOTS; i++)
|
||||||
Remove(i);
|
RemoveInternal(i);
|
||||||
RemoveAux();
|
RemoveAuxInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Insert(UINT slot, SS_CARDTYPE type);
|
void Insert(UINT slot, SS_CARDTYPE type);
|
||||||
|
@ -34,7 +34,6 @@ public:
|
||||||
Card& GetRef(UINT slot)
|
Card& GetRef(UINT slot)
|
||||||
{
|
{
|
||||||
SS_CARDTYPE t=QuerySlot(slot); _ASSERT((t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2) && m_slot[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];
|
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]; }
|
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:
|
private:
|
||||||
void RemoveInternal(UINT slot);
|
void RemoveInternal(UINT slot);
|
||||||
|
void RemoveAuxInternal();
|
||||||
|
|
||||||
Card* m_slot[NUM_SLOTS];
|
Card* m_slot[NUM_SLOTS];
|
||||||
Card* m_aux;
|
Card* m_aux;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user