1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-15 00:02:49 +03:00

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).
This commit is contained in:
Adriano Cunha
2024-01-18 12:26:18 -08:00
committed by GitHub
parent d5eb265f78
commit b3b9276bf9

View File

@ -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();