From 17617ce031c6e2c521be5450966edce4399e45d6 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:38:16 +0200 Subject: [PATCH] Fix possible memory leak in NeighborInfo Module (#2765) Co-authored-by: Ben Meadors --- src/modules/NeighborInfoModule.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index e83436552..a0e9843ed 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -104,16 +104,6 @@ NeighborInfoModule::NeighborInfoModule() } } -/* -Allocate a zeroed neighbor info packet -*/ -meshtastic_NeighborInfo *NeighborInfoModule::allocateNeighborInfoPacket() -{ - meshtastic_NeighborInfo *neighborInfo = (meshtastic_NeighborInfo *)malloc(sizeof(meshtastic_NeighborInfo)); - memset(neighborInfo, 0, sizeof(meshtastic_NeighborInfo)); - return neighborInfo; -} - /* Collect neighbor info from the nodeDB's history, capping at a maximum number of entries and max time Assumes that the neighborInfo packet has been allocated @@ -185,14 +175,14 @@ size_t NeighborInfoModule::cleanUpNeighbors() /* Send neighbor info to the mesh */ void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies) { - meshtastic_NeighborInfo *neighborInfo = allocateNeighborInfoPacket(); - collectNeighborInfo(neighborInfo); - meshtastic_MeshPacket *p = allocDataProtobuf(*neighborInfo); + meshtastic_NeighborInfo neighborInfo = meshtastic_NeighborInfo_init_zero; + collectNeighborInfo(&neighborInfo); + meshtastic_MeshPacket *p = allocDataProtobuf(neighborInfo); // send regardless of whether or not we have neighbors in our DB, // because we want to get neighbors for the next cycle p->to = dest; p->decoded.want_response = wantReplies; - printNeighborInfo("SENDING", neighborInfo); + printNeighborInfo("SENDING", &neighborInfo); service.sendToMesh(p, RX_SRC_LOCAL, true); }