Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions src/u-blox_GNSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ void DevUBLOXGNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t req
// by other threads without overwriting the requested / expected Class and ID.
volatile static uint8_t storedClass = 0;
volatile static uint8_t storedID = 0;
static size_t payloadAutoBytes;
if (requestedClass || requestedID) // If either is non-zero, store the requested Class and ID
{
storedClass = requestedClass;
Expand Down Expand Up @@ -1695,21 +1696,28 @@ void DevUBLOXGNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t req
}
#endif
}
if (payloadAuto != nullptr) // Check if memory is already allocated - this should be impossible!

// Determine the payload length
if ((!logBecauseAuto) && (logBecauseEnabled))
maxPayload = SFE_UBX_MAX_LENGTH;

// Increase the payloadAuto buffer size if necessary, by removing
// the previous buffer
if (payloadAuto && (payloadAutoBytes < maxPayload))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
{
_debugSerial.println(F("process: memory is already allocated for payloadAuto! Deleting..."));
}
#endif
delete[] payloadAuto; // Created with new[]
delete[] payloadAuto; // Created with new[] below
payloadAuto = nullptr;
packetAuto.payload = payloadAuto;
payloadAutoBytes = 0;
}
if ((!logBecauseAuto) && (logBecauseEnabled))
maxPayload = SFE_UBX_MAX_LENGTH;
payloadAuto = new uint8_t[maxPayload]; // Allocate RAM for payloadAuto

// Allocate the payloadAuto buffer if necessary
if (payloadAuto == nullptr)
{
payloadAuto = new uint8_t[maxPayload];
if (payloadAuto)
payloadAutoBytes = maxPayload;
}

packetAuto.payload = payloadAuto;
if (payloadAuto == nullptr) // Check if the alloc failed
{
Expand Down Expand Up @@ -3271,11 +3279,7 @@ void DevUBLOXGNSS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t
// Now that the packet is complete and has been processed, we need to delete the memory
// allocated for packetAuto
if (activePacketBuffer == SFE_UBLOX_PACKET_PACKETAUTO)
{
delete[] payloadAuto; // Created with new[]
payloadAuto = nullptr;
packetAuto.payload = payloadAuto;
}
packetAuto.payload = nullptr;
}
else // Load this byte into the payload array
{
Expand Down