Skip to content

Commit

Permalink
Leaks fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed May 17, 2023
1 parent dda358f commit d97ac81
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/lib/cache/subCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,11 @@ bool subCacheItemInsert
{
if (orionldState.apiVersion == NGSI_LD_V1)
{
// FIXME: Instead of calling qBuild here, I should pass the pointer from pCheckSubscription
if (cSubP->qP != NULL)
qRelease(cSubP->qP);
cSubP->qP = qBuild(q.c_str(), &cSubP->qText, &validForV2, &isMq, true); // cSubP->qText needs real allocation

if (cSubP->qText != NULL)
cSubP->qText = strdup(cSubP->qText);
else
Expand Down
8 changes: 0 additions & 8 deletions src/lib/orionld/common/subCacheApiSubscriptionInsert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ CachedSubscription* subCacheApiSubscriptionInsert(KjNode* apiSubscriptionP, QNod
cSubP->lastFailure = lastFailureP->value.f;

if (descriptionP != NULL)
{
if (cSubP->description != NULL)
free(cSubP->description);
cSubP->description = strdup(descriptionP->value.s);
}

if (qP != NULL)
cSubP->expression.q = qP->value.s;
Expand All @@ -133,11 +129,7 @@ CachedSubscription* subCacheApiSubscriptionInsert(KjNode* apiSubscriptionP, QNod
cSubP->expression.mq = mqP->value.s;

if (ldqP != NULL)
{
if (cSubP->qText != NULL)
free(cSubP->qText);
cSubP->qText = strdup(ldqP->value.s);
}

if (isActiveP != NULL)
{
Expand Down
2 changes: 0 additions & 2 deletions src/lib/orionld/q/qBuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
//
QNode* qBuild(const char* q, char** qRenderP, bool* v2ValidP, bool* isMqP, bool qToDbModel)
{
LM_T(LmtQ, ("In qBuild: %s", q));

QNode* qP = NULL;
char* title;
char* detail;
Expand Down
26 changes: 26 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldPatchSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern "C"
#include "orionld/context/orionldAttributeExpand.h" // orionldAttributeExpand
#include "orionld/payloadCheck/PCHECK.h" // PCHECK_URI
#include "orionld/payloadCheck/pCheckSubscription.h" // pCheckSubscription
#include "orionld/q/qRelease.h" // qRelease
#include "orionld/mongoc/mongocSubscriptionLookup.h" // mongocSubscriptionLookup
#include "orionld/mongoc/mongocSubscriptionReplace.h" // mongocSubscriptionReplace
#include "orionld/dbModel/dbModelFromApiSubscription.h" // dbModelFromApiSubscription
Expand Down Expand Up @@ -319,7 +320,16 @@ static void fixDbSubscription(KjNode* dbSubscriptionP, char* qRenderedForDb)
//
static bool subCacheItemUpdateEntities(CachedSubscription* cSubP, KjNode* entityArray)
{
//
// To replace "entities", we first need to frre up the old "entities"
//
for (long unsigned int ix = 0; ix < cSubP->entityIdInfos.size(); ix++)
{
cSubP->entityIdInfos[ix]->release();
delete cSubP->entityIdInfos[ix];
}
cSubP->entityIdInfos.clear();

for (KjNode* entityP = entityArray->value.firstChildP; entityP != NULL; entityP = entityP->next)
{
KjNode* idP = kjLookup(entityP, "id");
Expand Down Expand Up @@ -588,7 +598,11 @@ static bool subCacheItemUpdate(OrionldTenant* tenantP, const char* subscriptionI
}

if (qNodeP != NULL)
{
if (cSubP->qP != NULL)
qRelease(cSubP->qP);
cSubP->qP = qNodeP;
}

for (KjNode* itemP = subscriptionTree->value.firstChildP; itemP != NULL; itemP = itemP->next)
{
Expand Down Expand Up @@ -809,6 +823,8 @@ bool orionldPatchSubscription(void)
&mqttChange);
if (r == false)
{
if (qNodeP != NULL)
qRelease(qNodeP);
LM_E(("pCheckSubscription FAILED"));
return false;
}
Expand All @@ -820,6 +836,8 @@ bool orionldPatchSubscription(void)

if (dbSubscriptionP == NULL)
{
if (qNodeP != NULL)
qRelease(qNodeP);
orionldError(OrionldResourceNotFound, "Subscription not found", subscriptionId, 404);
return false;
}
Expand Down Expand Up @@ -875,7 +893,11 @@ bool orionldPatchSubscription(void)
CachedSubscription* cSubP = subCacheItemLookup(orionldState.tenantP->tenant, subscriptionId);

if (ngsildSubscriptionPatch(dbSubscriptionP, cSubP, orionldState.requestTree, qP, geoqP, qRenderedForDb) == false)
{
if (qNodeP != NULL)
qRelease(qNodeP);
LM_RE(false, ("ngsildSubscriptionPatch failed!"));
}

//
// Update modifiedAt
Expand All @@ -898,6 +920,8 @@ bool orionldPatchSubscription(void)
mqttInfoFromDbTree(dbSubscriptionP, newUriP, &newMqttInfo);
if (mqttConnectFromInfo(&newMqttInfo) == false)
{
if (qNodeP != NULL)
qRelease(qNodeP);
orionldError(OrionldInternalError, "MQTT Error", "unable to connect to MQTT broker", 500);
return false;
}
Expand All @@ -915,6 +939,8 @@ bool orionldPatchSubscription(void)
//
if (mongocSubscriptionReplace(subscriptionId, dbSubscriptionP) == false)
{
if (qNodeP != NULL)
qRelease(qNodeP);
orionldError(OrionldInternalError, "Database Error", "patching a subscription", 500);
return false;
}
Expand Down

0 comments on commit d97ac81

Please sign in to comment.