Fix memory leak in NextHopRouter: always free packet copy when removing from pending

This commit is contained in:
Mike Robbins 2025-09-12 10:40:13 -07:00 committed by Ben Meadors
parent ac4bcd2f56
commit 962e5d513c

View File

@ -175,12 +175,18 @@ bool NextHopRouter::stopRetransmission(GlobalPacketId key)
config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER_LATE)) {
// remove the 'original' (identified by originator and packet->id) from the txqueue and free it
cancelSending(getFrom(p), p->id);
// now free the pooled copy for retransmission too
packetPool.release(p);
}
}
// Regardless of whether or not we canceled this packet from the txQueue, remove it from our pending list so it doesn't
// get scheduled again. (This is the core of stopRetransmission.)
auto numErased = pending.erase(key);
assert(numErased == 1);
// When we remove an entry from pending, always be sure to release the copy of the packet that was allocated in the call
// to startRetransmission.
packetPool.release(p);
return true;
} else
return false;