Skip to content

Commit 7212b9a

Browse files
committed
fix memory leak when reconnect
1 parent 9694d7f commit 7212b9a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

MicroGear.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ MicroGear::MicroGear(Client& netclient ) {
8989
sockclient = &netclient;
9090
constate = CLIENT_NOTCONNECT;
9191
authclient = NULL;
92+
mqttclient = NULL;
9293

9394
this->token = NULL;
9495
this->tokensecret = NULL;
@@ -379,8 +380,8 @@ boolean MicroGear::connect(char* appid) {
379380
p++;
380381
}
381382

383+
if (mqttclient) delete(mqttclient);
382384
mqttclient = new PubSubClient(endpoint, *p=='\0'?1883:atoi(p), msgCallback, *sockclient);
383-
384385
delay(500);
385386

386387
constate = this->mqttclient->connect(token,username+TOKENSIZE+1,password);

0 commit comments

Comments
 (0)