Add null check for packet allocation and clean up Dispatcher

This commit is contained in:
João Brázio
2025-07-08 16:02:10 +01:00
parent ac056fb0b9
commit 92ee1820c4
2 changed files with 14 additions and 8 deletions

View File

@@ -774,9 +774,16 @@ public:
#endif #endif
if (f16 == crc) { if (f16 == crc) {
mesh::Packet *pkt = _mgr->allocNew(); Packet *pkt = _mgr->allocNew();
pkt->readFrom(bytes, len);
_mgr->queueInbound(pkt, millis()); if (pkt != NULL) {
pkt->readFrom(bytes, len);
_mgr->queueInbound(pkt, millis());
} else {
#if MESH_PACKET_LOGGING
Serial.printf("BRIDGE: Unable to allocate new Packet *pkt");
#endif
}
} }
} }
} }

View File

@@ -1,7 +1,7 @@
#include "Dispatcher.h" #include "Dispatcher.h"
#if MESH_PACKET_LOGGING #if MESH_PACKET_LOGGING
#include <Arduino.h> #include <Arduino.h>
#endif #endif
#include <math.h> #include <math.h>
@@ -104,7 +104,6 @@ void Dispatcher::loop() {
processRecvPacket(pkt); processRecvPacket(pkt);
} }
} }
checkRecv(); checkRecv();
checkSend(); checkSend();
} }
@@ -116,7 +115,6 @@ void Dispatcher::checkRecv() {
{ {
uint8_t raw[MAX_TRANS_UNIT+1]; uint8_t raw[MAX_TRANS_UNIT+1];
int len = _radio->recvRaw(raw, MAX_TRANS_UNIT); int len = _radio->recvRaw(raw, MAX_TRANS_UNIT);
if (len > 0) { if (len > 0) {
logRxRaw(_radio->getLastSNR(), _radio->getLastRSSI(), raw, len); logRxRaw(_radio->getLastSNR(), _radio->getLastRSSI(), raw, len);
@@ -282,7 +280,7 @@ void Dispatcher::checkSend() {
} }
outbound_expiry = futureMillis(max_airtime); outbound_expiry = futureMillis(max_airtime);
#if MESH_PACKET_LOGGING #if MESH_PACKET_LOGGING
Serial.print(getLogDateTime()); Serial.print(getLogDateTime());
Serial.printf(": TX, len=%d (type=%d, route=%s, payload_len=%d)", Serial.printf(": TX, len=%d (type=%d, route=%s, payload_len=%d)",
len, outbound->getPayloadType(), outbound->isRouteDirect() ? "D" : "F", outbound->payload_len); len, outbound->getPayloadType(), outbound->isRouteDirect() ? "D" : "F", outbound->payload_len);
@@ -292,7 +290,7 @@ void Dispatcher::checkSend() {
} else { } else {
Serial.printf("\n"); Serial.printf("\n");
} }
#endif #endif
} }
} }
} }
@@ -330,4 +328,5 @@ bool Dispatcher::millisHasNowPassed(unsigned long timestamp) const {
unsigned long Dispatcher::futureMillis(int millis_from_now) const { unsigned long Dispatcher::futureMillis(int millis_from_now) const {
return _ms->getMillis() + millis_from_now; return _ms->getMillis() + millis_from_now;
} }
} }