-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedWe'd welcome help on this issueWe'd welcome help on this issue
Description
Category
Other
Hardware
Not Applicable
Firmware Version
2.5.16.f81d3b0
Description
I believe there are two potential memory leaks in src/mqtt/MQTT.cpp MQTT::onReceive
-
Any pointers within the
Line 148 in 761a99d
return; meshtastic_ServiceEnvelopethat are non-NULL are leaked. -
The
Line 202 in 761a99d
if (isToUs(p) || (tx && tx->has_user && rx && rx->has_user)) meshtastic_MeshPacket *pis leaked when theifstatement evaluates tofalse
There are several places in MQTT::onReceive where calls to free/release are needed. If I may offer a suggestion; use std::unique_ptr to help ensure these are always freed/released on return
Example:
// make sure to free both strings and the MeshPacket (passing in NULL is acceptable)
struct ServiceEnvelopeCleaner {
void operator()(meshtastic_ServiceEnvelope *e)
{
free(e->channel_id);
free(e->gateway_id);
free(e->packet);
}
};
using ScopedServiceEnvelopeReleaser = std::unique_ptr<meshtastic_ServiceEnvelope, ServiceEnvelopeCleaner>;
struct PacketPoolMeshPacketReleaser {
void operator()(meshtastic_MeshPacket *p)
{
packetPool.release(p);
}
};
using PacketPoolMeshPacketPtr = std::unique_ptr<meshtastic_MeshPacket, PacketPoolMeshPacketReleaser>;
...
ScopedServiceEnvelopeReleaser cleanup_e(&e);
...
PacketPoolMeshPacketPtr p(packetPool.allocCopy(*e.packet));
...
router->enqueueReceivedMessage(p.release());Relevant log output
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedWe'd welcome help on this issueWe'd welcome help on this issue