Skip to content

Commit aef6ce4

Browse files
authored
Check and fix valgrind errors (telefonicaid#4709)
* FIX phony modification to trigger valgrind check * FIX leaks * FIX leaks
1 parent 7ba8f52 commit aef6ce4

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/lib/apiTypesV2/GeoFilter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ GeoFilter::GeoFilter()
5353

5454

5555

56+
/* ****************************************************************************
57+
*
58+
* GeoFilter::~GeoFilter -
59+
*/
60+
GeoFilter::~GeoFilter()
61+
{
62+
release();
63+
}
64+
65+
66+
5667
/* ****************************************************************************
5768
*
5869
* pointVectorRelease -

src/lib/apiTypesV2/GeoFilter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef struct GeoFilter
4747
orion::Georel georel;
4848

4949
GeoFilter();
50+
~GeoFilter();
5051

5152
int fill(const std::string& geometry,
5253
const std::string& coords,

src/lib/mongoBackend/mongoCreateSubscription.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ static void insertInCache
6565
double now
6666
)
6767
{
68-
// set strinFilterP and mdStringFilterP (they will be used later in subCacheItemInsert)
68+
// set stringFilterP and mdStringFilterP (they will be used later in subCacheItemInsert)
6969
std::string err;
7070

7171
StringFilter* stringFilterP = sub.subject.condition.expression.stringFilter.clone(&err);
7272
if (stringFilterP == NULL)
7373
{
74-
LM_E(("Runtime Error (cloning stringFilter: %s", err.c_str()));
74+
LM_E(("Runtime Error (cloning stringFilter: %s)", err.c_str()));
7575
return;
7676
}
7777
StringFilter* mdStringFilterP = sub.subject.condition.expression.mdStringFilter.clone(&err);
78-
if (stringFilterP == NULL)
78+
if (mdStringFilterP == NULL)
7979
{
80-
LM_E(("Runtime Error (cloning mdStringFilterP: %s", err.c_str()));
80+
delete stringFilterP;
81+
LM_E(("Runtime Error (cloning mdStringFilterP: %s)", err.c_str()));
8182
return;
8283
}
8384

@@ -118,6 +119,11 @@ static void insertInCache
118119
sub.subject.condition.notifyOnMetadataChange);
119120

120121
cacheSemGive(__FUNCTION__, "Inserting subscription in cache");
122+
123+
// Release dynamic memory allocated by clone() methods
124+
// (note stringFilterP and mdStringFilterP can be not NULL as that condition is already checked above)
125+
delete stringFilterP;
126+
delete mdStringFilterP;
121127
}
122128

123129

src/lib/mongoBackend/mongoUpdateSubscription.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ static void updateInCache
151151
StringFilter* stringFilterP = subUp.subject.condition.expression.stringFilter.clone(&err);
152152
if (stringFilterP == NULL)
153153
{
154-
LM_E(("Runtime Error (cloning stringFilter: %s", err.c_str()));
154+
LM_E(("Runtime Error (cloning stringFilter: %s)", err.c_str()));
155155
return;
156156
}
157157

158158
StringFilter* mdStringFilterP = subUp.subject.condition.expression.mdStringFilter.clone(&err);
159-
if (stringFilterP == NULL)
159+
if (mdStringFilterP == NULL)
160160
{
161-
LM_E(("Runtime Error (cloning mdStringFilterP: %s", err.c_str()));
161+
delete stringFilterP;
162+
LM_E(("Runtime Error (cloning mdStringFilterP: %s)", err.c_str()));
162163
return;
163164
}
164165

@@ -306,6 +307,11 @@ static void updateInCache
306307
}
307308

308309
cacheSemGive(__FUNCTION__, "Updating cached subscription");
310+
311+
// Release dynamic memory allocated by clone() methods
312+
// (note stringFilterP and mdStringFilterP can be not NULL as that condition is already checked above)
313+
delete stringFilterP;
314+
delete mdStringFilterP;
309315
}
310316

311317

0 commit comments

Comments
 (0)