Skip to content

Commit

Permalink
Set global pointers to null after free
Browse files Browse the repository at this point in the history
Fixes crash when restarting MQTT.
  • Loading branch information
nseidle committed Mar 21, 2024
1 parent c7466c9 commit df481a4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Firmware/RTK_Everywhere/MQTT_Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,17 @@ void mqttClientStop(bool shutdown)
}

// Release the buffers
if (mqttClientPrivateKeyBuffer)
if (mqttClientPrivateKeyBuffer != nullptr)
{
free(mqttClientPrivateKeyBuffer);
if (mqttClientCertificateBuffer)
mqttClientPrivateKeyBuffer = nullptr;
}

if (mqttClientCertificateBuffer != nullptr)
{
free(mqttClientCertificateBuffer);
mqttClientCertificateBuffer = nullptr;
}

reportHeapNow(settings.debugMqttClientState);

Expand Down Expand Up @@ -559,12 +566,14 @@ void mqttClientUpdate()
if (mqttClientCertificateBuffer)
{
free(mqttClientCertificateBuffer);
mqttClientCertificateBuffer = nullptr;
systemPrintln("Failed to allocate key buffer!");
}

if (mqttClientPrivateKeyBuffer)
{
free(mqttClientPrivateKeyBuffer);
mqttClientPrivateKeyBuffer = nullptr;
systemPrintln("Failed to allocate certificate buffer!");
}

Expand Down

0 comments on commit df481a4

Please sign in to comment.