[colobot] 10/74: Fix memory leak related to performance counters
Didier Raboud
odyx at moszumanska.debian.org
Mon Nov 7 07:49:59 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 210b5c295d601ffea7acdb3a7505e0102571bc6f
Author: krzys-h <krzys_h at interia.pl>
Date: Sun Jul 24 22:51:41 2016 +0200
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 5fea22ff03f3da5ee27be4039205010c203a8c23)
* DestroyTimeStamp leaving null pointers in CSystemUtils::m_timeStamps (this was introduced by @piotrdz long ago when introducing smart pointers)
---
src/common/profiler.cpp | 2 ++
src/common/system/system.cpp | 7 ++-----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/common/profiler.cpp b/src/common/profiler.cpp
index f94a92e..f80ae84 100644
--- a/src/common/profiler.cpp
+++ b/src/common/profiler.cpp
@@ -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)
diff --git a/src/common/system/system.cpp b/src/common/system/system.cpp
index 210b4a7..ce594ea 100644
--- a/src/common/system/system.cpp
+++ b/src/common/system/system.cpp
@@ -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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list