Skip to content

Commit 06adcee

Browse files
committed
Prevent memory leak in pointperfectTryZtpToken. Also:
Correct debugPpCertificate print Do secureClient.stop in pointperfectUpdateKeys
1 parent 471f331 commit 06adcee

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Firmware/RTK_Everywhere/menuPP.ino

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ ZtpResponse pointperfectTryZtpToken(String &ztpRequest)
555555
strncpy(tempHolderPtr, (const char *)((*jsonZtp)["privateKey"]), MQTT_CERT_SIZE - 1);
556556
recordFile("privateKey", tempHolderPtr, strlen(tempHolderPtr));
557557

558+
free(tempHolderPtr); // Clean up. Done with tempHolderPtr
559+
558560
// Validate the keys
559561
if (!checkCertificates())
560562
{
@@ -732,7 +734,10 @@ bool checkCertificates()
732734
free(keyContents);
733735

734736
if (settings.debugPpCertificate)
735-
systemPrintln("Stored certificates are valid!");
737+
{
738+
systemPrintf("Stored certificates are %svalid\r\n", validCertificates ? "" : "NOT ");
739+
}
740+
736741
return (validCertificates);
737742
}
738743

@@ -816,6 +821,7 @@ bool pointperfectUpdateKeys()
816821
do
817822
{
818823
// Allocate the buffers
824+
// Freed outside the do loop
819825
if (online.psram == true)
820826
{
821827
certificateContents = (char *)ps_malloc(MQTT_CERT_SIZE);
@@ -829,8 +835,6 @@ bool pointperfectUpdateKeys()
829835

830836
if ((!certificateContents) || (!keyContents))
831837
{
832-
if (certificateContents)
833-
free(certificateContents);
834838
systemPrintln("Failed to allocate content buffers!");
835839
break;
836840
}
@@ -858,6 +862,8 @@ bool pointperfectUpdateKeys()
858862
// Configure the MQTT client
859863
menuppMqttClient->setId(settings.pointPerfectClientID);
860864
menuppMqttClient->onMessage(mqttCallback);
865+
menuppMqttClient->setKeepAliveInterval(10 * 1000);
866+
menuppMqttClient->setConnectionTimeout( 5 * 1000);
861867

862868
// Attempt to the MQTT broker
863869
systemPrintf("Attempting to connect to MQTT broker: %s\r\n", settings.pointPerfectBrokerHost);
@@ -933,6 +939,8 @@ bool pointperfectUpdateKeys()
933939
menuppMqttClient = nullptr;
934940
}
935941

942+
secureClient.stop();
943+
936944
// Free the content buffers
937945
if (keyContents)
938946
free(keyContents);

0 commit comments

Comments
 (0)