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)
dev-new-models
parent
dbe7fd6ef0
commit
210b5c295d
src/common
system
|
@ -53,6 +53,8 @@ void CProfiler::StopPerformanceCounter(PerformanceCounter counter)
|
||||||
SystemTimeStamp* timeStamp = m_systemUtils->CreateTimeStamp();
|
SystemTimeStamp* timeStamp = m_systemUtils->CreateTimeStamp();
|
||||||
m_systemUtils->GetCurrentTimeStamp(timeStamp);
|
m_systemUtils->GetCurrentTimeStamp(timeStamp);
|
||||||
m_performanceCounters[counter] += m_systemUtils->TimeStampExactDiff(m_runningPerformanceCounters.top(), timeStamp);
|
m_performanceCounters[counter] += m_systemUtils->TimeStampExactDiff(m_runningPerformanceCounters.top(), timeStamp);
|
||||||
|
m_systemUtils->DestroyTimeStamp(timeStamp);
|
||||||
|
m_systemUtils->DestroyTimeStamp(m_runningPerformanceCounters.top());
|
||||||
m_runningPerformanceCounters.pop();
|
m_runningPerformanceCounters.pop();
|
||||||
|
|
||||||
if (counter == PCNT_ALL)
|
if (counter == PCNT_ALL)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<CSystemUtils> CSystemUtils::Create()
|
std::unique_ptr<CSystemUtils> CSystemUtils::Create()
|
||||||
|
@ -152,11 +153,7 @@ SystemTimeStamp* CSystemUtils::CreateTimeStamp()
|
||||||
|
|
||||||
void CSystemUtils::DestroyTimeStamp(SystemTimeStamp *stamp)
|
void CSystemUtils::DestroyTimeStamp(SystemTimeStamp *stamp)
|
||||||
{
|
{
|
||||||
for (auto& timeStamp : m_timeStamps)
|
m_timeStamps.erase(std::remove_if(m_timeStamps.begin(), m_timeStamps.end(), [&](const std::unique_ptr<SystemTimeStamp>& timeStamp) { return timeStamp.get() == stamp; }));
|
||||||
{
|
|
||||||
if (timeStamp.get() == stamp)
|
|
||||||
timeStamp.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSystemUtils::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)
|
void CSystemUtils::CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)
|
||||||
|
|
Loading…
Reference in New Issue