@@ -112,7 +112,8 @@ const char MQTT_TOPIC_ASSISTNOW[] = "/pp/ubx/mga"; // AssistNow (MGA) topic
112
112
113
113
static MqttClient *mqttClient;
114
114
115
- static char *mqttClientCertificateBuffer; // Buffer for client certificate
115
+ static char *mqttClientCertificateBuffer = nullptr ; // Buffer for client certificate
116
+ static char *mqttClientPrivateKeyBuffer = nullptr ; // Buffer for client private key
116
117
117
118
// Throttle the time between connection attempts
118
119
static int mqttClientConnectionAttempts; // Count the number of connection attempts between restarts
@@ -121,8 +122,6 @@ static int mqttClientConnectionAttemptsTotal; // Count the number of connection
121
122
122
123
static volatile uint32_t mqttClientLastDataReceived; // Last time data was received via MQTT
123
124
124
- static char *mqttClientPrivateKeyBuffer; // Buffer for client private key
125
-
126
125
static NetworkSecureWiFiClient *mqttSecureClient;
127
126
128
127
static volatile uint8_t mqttClientState = MQTT_CLIENT_OFF;
@@ -564,15 +563,20 @@ void mqttClientUpdate()
564
563
}
565
564
566
565
// Allocate the buffers
566
+ // Freed by mqttClientShutdown / mqttClientStop
567
567
if (online.psram == true )
568
568
{
569
- mqttClientCertificateBuffer = (char *)ps_malloc (MQTT_CERT_SIZE);
570
- mqttClientPrivateKeyBuffer = (char *)ps_malloc (MQTT_CERT_SIZE);
569
+ if (!mqttClientCertificateBuffer)
570
+ mqttClientCertificateBuffer = (char *)ps_malloc (MQTT_CERT_SIZE);
571
+ if (!mqttClientPrivateKeyBuffer)
572
+ mqttClientPrivateKeyBuffer = (char *)ps_malloc (MQTT_CERT_SIZE);
571
573
}
572
574
else
573
575
{
574
- mqttClientCertificateBuffer = (char *)malloc (MQTT_CERT_SIZE);
575
- mqttClientPrivateKeyBuffer = (char *)malloc (MQTT_CERT_SIZE);
576
+ if (!mqttClientCertificateBuffer)
577
+ mqttClientCertificateBuffer = (char *)malloc (MQTT_CERT_SIZE);
578
+ if (!mqttClientPrivateKeyBuffer)
579
+ mqttClientPrivateKeyBuffer = (char *)malloc (MQTT_CERT_SIZE);
576
580
}
577
581
578
582
if ((!mqttClientCertificateBuffer) || (!mqttClientPrivateKeyBuffer))
0 commit comments