Skip to content

Commit

Permalink
Avoid NPE and "multi-deinitialization" of ArduinoOTA (esp8266#9058)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
adrcunha authored and hasenradball committed Nov 18, 2024
1 parent 5616518 commit e3397ff
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,14 @@ void ArduinoOTAClass::_runUpdate() {
}

void ArduinoOTAClass::end() {
if (!_initialized)
return;

_initialized = false;
_udp_ota->unref();
_udp_ota = 0;
if(_udp_ota){
_udp_ota->unref();
_udp_ota = 0;
}
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
if(_useMDNS){
MDNS.end();
Expand Down

0 comments on commit e3397ff

Please sign in to comment.