Skip to content

Commit c4f3a53

Browse files
committed
[N001] Add pointer null-checks, close client also when connection fails
1 parent 91d27bd commit c4f3a53

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/src/NotifierStructs/N001_data_struct.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
4141
secureClient.setInsecure();
4242
client = &secureClient;
4343
} else {
44-
client = new WiFiClient();
44+
client = new (std::nothrow) WiFiClient();
45+
46+
if (!client) { return false; }
4547
}
4648

4749
# else // if FEATURE_EMAIL_TLS
4850

4951
// Use WiFiClient class to create TCP connections
50-
client = new WiFiClient();
52+
client = new (std::nothrow) WiFiClient();
53+
54+
if (!client) { return false; }
5155
# endif // if FEATURE_EMAIL_TLS
5256

5357
# ifdef MUSTFIX_CLIENT_TIMEOUT_IN_SECONDS
@@ -355,18 +359,18 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
355359
}
356360
}
357361

358-
// client.PR_9453_FLUSH_TO_CLEAR();
359-
client->stop();
360-
delete client;
361-
362-
if (myStatus == true) {
362+
if (myStatus) {
363363
addLog(LOG_LEVEL_INFO, F("Email: Connection Closed Successfully"));
364364
} else {
365365
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
366366
addLogMove(LOG_LEVEL_ERROR, concat(F("Email: Connection Closed With Error. Used header: "), mailheader));
367367
}
368368
}
369369
}
370+
371+
client->stop();
372+
delete client;
373+
370374
return myStatus;
371375
}
372376

0 commit comments

Comments
 (0)