Skip to content

Commit 541bd2b

Browse files
committed
Correction of memory leaks
1 parent e102801 commit 541bd2b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

loop-functions/vanilla/ForagingTwoSpotsLoopFunc.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ForagingTwoSpotsLoopFunction::ForagingTwoSpotsLoopFunction() {
1818
m_cCoordSpot2 = CVector2(-0.75,0);
1919
m_fObjectiveFunction = 0;
2020
m_bInitializationStep = true;
21+
m_punFoodData = NULL;
2122
}
2223

2324
/****************************************/
@@ -36,14 +37,14 @@ void ForagingTwoSpotsLoopFunction::Init(TConfigurationNode& t_tree) {
3637
/****************************************/
3738
/****************************************/
3839

39-
ForagingTwoSpotsLoopFunction::~ForagingTwoSpotsLoopFunction() {}
40+
ForagingTwoSpotsLoopFunction::~ForagingTwoSpotsLoopFunction() {
41+
delete[] m_punFoodData;
42+
}
4043

4144
/****************************************/
4245
/****************************************/
4346

44-
void ForagingTwoSpotsLoopFunction::Destroy() {
45-
delete[] m_punFoodData;
46-
}
47+
void ForagingTwoSpotsLoopFunction::Destroy() {}
4748

4849
/****************************************/
4950
/****************************************/
@@ -72,12 +73,15 @@ argos::CColor ForagingTwoSpotsLoopFunction::GetFloorColor(const argos::CVector2&
7273

7374
void ForagingTwoSpotsLoopFunction::Reset() {
7475
std::ios::sync_with_stdio(false);
75-
m_fObjectiveFunction = 0;
76-
m_punFoodData = new UInt32[m_unNumberRobots+1];
76+
if (m_punFoodData == NULL) {
77+
m_punFoodData = new UInt32[m_unNumberRobots+1];
78+
}
7779
for (UInt32 i = m_unNumberRobots; i <= m_unNumberRobots; i++) {
7880
m_punFoodData[i] = 0;
7981
}
80-
m_bInitializationStep = true;
82+
83+
m_fObjectiveFunction = 0;
84+
m_bInitializationStep = false;
8185
}
8286

8387
/****************************************/

0 commit comments

Comments
 (0)