Skip to content

Commit

Permalink
Fix memleak in MQTT code
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Sep 26, 2024
1 parent b996a5c commit d2d991f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/bin/calaos_server/IO/Mqtt/MqttExternProc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class MqttProcess: public ExternProcClient
virtual int procMain();

EXTERN_PROC_CLIENT_CTOR(MqttProcess)
virtual ~MqttProcess();

protected:
MqttClient *m_client;
Expand All @@ -125,6 +126,12 @@ class MqttProcess: public ExternProcClient

};

MqttProcess::~MqttProcess()
{
delete m_client;
mosqpp::lib_cleanup();
}

void MqttProcess::readTimeout()
{
m_client->loop(0, 1);
Expand All @@ -138,8 +145,6 @@ void MqttProcess::messageReceived(const string &msg)
if (!jroot)
{
cWarningDom("mqtt") << "Error parsing json from sub process: " << jerr.text;
if (jroot)
json_decref(jroot);
return;
}

Expand Down Expand Up @@ -191,6 +196,7 @@ bool MqttProcess::setup(int &argc, char **&argv)

Params p;
jansson_decode_object(jroot, p);
json_decref(jroot);

if (p.Exists("host"))
host = p["host"];
Expand Down Expand Up @@ -235,6 +241,7 @@ bool MqttProcess::setup(int &argc, char **&argv)
json_object_set_new(root, "payload", json_string((const char*)m->payload));
cDebugDom("mqtt") << "Send : " << json_dumps(root, 0);
sendMessage(json_dumps(root, 0));
json_decref(root);
});

return true;
Expand Down

0 comments on commit d2d991f

Please sign in to comment.