Skip to content

Commit b3b9276

Browse files
authored
Avoid NPE and "multi-deinitialization" of ArduinoOTA (#9058)
Avoid a null pointer exception when ArduinoOTA.end() is called more than once and thus the UDP socket is already freed. Also avoid unnecessary teardown if the class is not initialized yet (for example, begin() wasn't called yet, or end() is called multiple times).
1 parent d5eb265 commit b3b9276

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

libraries/ArduinoOTA/ArduinoOTA.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,14 @@ void ArduinoOTAClass::_runUpdate() {
359359
}
360360

361361
void ArduinoOTAClass::end() {
362+
if (!_initialized)
363+
return;
364+
362365
_initialized = false;
363-
_udp_ota->unref();
364-
_udp_ota = 0;
366+
if(_udp_ota){
367+
_udp_ota->unref();
368+
_udp_ota = 0;
369+
}
365370
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
366371
if(_useMDNS){
367372
MDNS.end();

0 commit comments

Comments
 (0)