Fix memory leak related to performance counters

This commit actually fixes two problems causing the leak:
* DestroyTimeStamp not being called in CProfiler (my stupid mistake in 5fea22ff03)
* DestroyTimeStamp leaving null pointers in CSystemUtils::m_timeStamps (this was introduced by @piotrdz long ago when introducing smart pointers)
master
krzys-h 2016-07-24 22:51:41 +02:00
parent dbe7fd6ef0
commit 210b5c295d
2 changed files with 4 additions and 5 deletions

View File

@ -53,6 +53,8 @@ void CProfiler::StopPerformanceCounter(PerformanceCounter counter)
SystemTimeStamp* timeStamp = m_systemUtils->CreateTimeStamp();
m_systemUtils->GetCurrentTimeStamp(timeStamp);
m_performanceCounters[counter] += m_systemUtils->TimeStampExactDiff(m_runningPerformanceCounters.top(), timeStamp);
m_systemUtils->DestroyTimeStamp(timeStamp);
m_systemUtils->DestroyTimeStamp(m_runningPerformanceCounters.top());
m_runningPerformanceCounters.pop();
if (counter == PCNT_ALL)

View File

@ -36,6 +36,7 @@
#include <cassert>
#include <iostream>
#include <algorithm>
std::unique_ptr<CSystemUtils> CSystemUtils::Create()
@ -152,11 +153,7 @@ SystemTimeStamp* CSystemUtils::CreateTimeStamp()
void CSystemUtils::DestroyTimeStamp(SystemTimeStamp *stamp)
{
for (auto& timeStamp : m_timeStamps)
{
if (timeStamp.get() == stamp)
timeStamp.reset();
}
m_timeStamps.erase(std::remove_if(m_timeStamps.begin(), m_timeStamps.end(), [&](const std::unique_ptr<SystemTimeStamp>& timeStamp) { return timeStamp.get() == stamp; }));
}
void CSystemUtils::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)