ArduinoOTA.end(); crashes ESP32

Hi,

I have issues with inbuild ArduinoOTA. In the beginning of my development I called ArduinoOTA.begin(); directly in setup() but have issues if Wifi is not enabled then. So I moved this to onWifiConnected event as all other network related stuff is started there after establishment of the connection…so far so good…

As done with e.g. NTP client I like to stopp everything in onWifiDisconnect event so calling ArduinoOTA.end(); which leads to the following exception. Even if it seems working fine without an explicit disconnect I like to understand what is going wrong? Is this a bug in the ArduinoOTA library that calling ArduinoOTA.end() causing this crash?

Cheers,
Nils

Components
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 @ 3.20009.0 (2.0.9)
  • tool-esptoolpy @ 1.40501.0 (4.5.1)
  • tool-mkfatfs @ 2.0.1
  • tool-mklittlefs @ 1.203.210628 (2.3)
  • tool-mkspiffs @ 2.230.0 (2.30)
  • tool-openocd-esp32 @ 2.1100.20220706 (11.0)
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5

Exception

CORRUPT HEAP: Bad head at 0x3ffd19c4. Expected 0xabba1234 got 0x3ffd0e2c

assert failed: multi_heap_free multi_heap_poisoning.c:253 (head != NULL)

Backtrace: 0x40083b81:0x3ffbaca0 0x4008d80d:0x3ffbacc0 0x400936b5:0x3ffbace0 0x40093327:0x3ffbae10 0x40084045:0x3ffbae30 0x400936e5:0x3ffbae50 0x4011cfa1:0x3ffbae70

#0 0x40083b81:0x3ffbaca0 in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:408
#1 0x4008d80d:0x3ffbacc0 in esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c:137
#2 0x400936b5:0x3ffbace0 in __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c:85
#3 0x40093327:0x3ffbae10 in multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:253
(inlined by) multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c:245
#4 0x40084045:0x3ffbae30 in heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c:361
#5 0x400936e5:0x3ffbae50 in free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/heap.c:39
#6 0x4011cfa1:0x3ffbae70 in timer_process_alarm at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_timer/src/esp_timer.c:334
(inlined by) timer_task at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_timer/src/esp_timer.c:386

ELF file SHA256: ac4ba91f083b443d

Rebooting…