Fixed memory leak with hintmessage. (#581)

Fixed memory leak with hintmessage.
This commit is contained in:
jeefo 2020-11-21 22:19:50 +03:00 committed by GitHub
parent 99954a2646
commit 519b7db38d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -15,10 +15,7 @@ CHintMessage::CHintMessage(const char *hintString, bool isHint, CUtlVector<const
CHintMessage::~CHintMessage()
{
for (int i = 0; i < m_args.Count(); i++)
delete[] m_args[i];
m_args.RemoveAll();
m_args.PurgeAndDeleteArrays();
}
void CHintMessage::Send(CBaseEntity *client)
@ -29,11 +26,7 @@ void CHintMessage::Send(CBaseEntity *client)
void CHintMessageQueue::Reset()
{
m_tmMessageEnd = 0;
for (int i = 0; i < m_messages.Count(); i++)
delete m_messages[i];
m_messages.RemoveAll();
m_messages.PurgeAndDeleteElements();
}
void CHintMessageQueue::Update(CBaseEntity *client)

View File

@ -99,6 +99,7 @@ void CBasePlayer::OnDestroy()
delete[] m_rebuyString;
m_rebuyString = nullptr;
}
m_hintMessageQueue.Reset();
}
#endif

View File

@ -121,6 +121,7 @@ public:
// Purges the list and calls delete on each element in it.
void PurgeAndDeleteElements();
void PurgeAndDeleteArrays();
// Set the size by which it grows when it needs to allocate more memory.
void SetGrowSize(int size);
@ -547,6 +548,15 @@ inline void CUtlVector<T>::PurgeAndDeleteElements()
Purge();
}
template <class T>
inline void CUtlVector<T>::PurgeAndDeleteArrays()
{
for (int i = 0; i < m_Size; i++)
delete[] Element(i);
Purge();
}
template <class T>
void CUtlVector<T>::SetGrowSize(int size)
{