Skip to content

Commit

Permalink
Fixed memory leak with hintmessage. (#581)
Browse files Browse the repository at this point in the history
Fixed memory leak with hintmessage.
  • Loading branch information
jeefo authored Nov 21, 2020
1 parent 99954a2 commit 519b7db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 2 additions & 9 deletions regamedll/dlls/hintmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void CBasePlayer::OnDestroy()
delete[] m_rebuyString;
m_rebuyString = nullptr;
}
m_hintMessageQueue.Reset();
}
#endif

Expand Down
10 changes: 10 additions & 0 deletions regamedll/public/utlvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class CUtlVector

// 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);
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 519b7db

Please sign in to comment.