Skip to content

Commit df481a4

Browse files
committed
Set global pointers to null after free
Fixes crash when restarting MQTT.
1 parent c7466c9 commit df481a4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Firmware/RTK_Everywhere/MQTT_Client.ino

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,17 @@ void mqttClientStop(bool shutdown)
437437
}
438438

439439
// Release the buffers
440-
if (mqttClientPrivateKeyBuffer)
440+
if (mqttClientPrivateKeyBuffer != nullptr)
441+
{
441442
free(mqttClientPrivateKeyBuffer);
442-
if (mqttClientCertificateBuffer)
443+
mqttClientPrivateKeyBuffer = nullptr;
444+
}
445+
446+
if (mqttClientCertificateBuffer != nullptr)
447+
{
443448
free(mqttClientCertificateBuffer);
449+
mqttClientCertificateBuffer = nullptr;
450+
}
444451

445452
reportHeapNow(settings.debugMqttClientState);
446453

@@ -559,12 +566,14 @@ void mqttClientUpdate()
559566
if (mqttClientCertificateBuffer)
560567
{
561568
free(mqttClientCertificateBuffer);
569+
mqttClientCertificateBuffer = nullptr;
562570
systemPrintln("Failed to allocate key buffer!");
563571
}
564572

565573
if (mqttClientPrivateKeyBuffer)
566574
{
567575
free(mqttClientPrivateKeyBuffer);
576+
mqttClientPrivateKeyBuffer = nullptr;
568577
systemPrintln("Failed to allocate certificate buffer!");
569578
}
570579

0 commit comments

Comments
 (0)