espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.46k stars 7.38k forks source link

BLEScan free() target pointer is outside heap areas #2210

Closed czuvich closed 5 years ago

czuvich commented 5 years ago

I'm using the latest Arduino Core build with a WROVER DEV Kit v4.1.

I am currently trying to perform a BLEScan, connect to the device and read some characteristics. When I establish a connection and call the BLERemoteService.getCharacteristic(UUID), I get the following exception after some logs:

assertion "heap != NULL && "free() target pointer is outside heap areas"" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c", line 268, function: heap_caps_free abort() was called at PC 0x401660ff on core 0

Here is the decoded backtrace:

Decoding stack results 0x40095070: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155 0x400952a1: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170 0x401660ff: __assert_func at ../../../.././newlib/libc/stdlib/assert.c line 63 0x40087c83: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c line 268 0x4008e6e9: _free_r at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/newlib/syscalls.c line 42 0x400dfbce: BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t) at /Users/Clay/Documents/Arduino/hardware/espressif/esp32/libraries/BLE/src/BLERemoteCharacteristic.cpp line 192 0x400e0625: BLERemoteService::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t) at /Users/Clay/Documents/Arduino/hardware/espressif/esp32/libraries/BLE/src/BLERemoteService.cpp line 120 0x400dedf1: BLEClient::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t) at /Users/Clay/Documents/Arduino/hardware/espressif/esp32/libraries/BLE/src/BLEClient.cpp line 314 0x400dfa41: BLEDevice::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t) at /Users/Clay/Documents/Arduino/hardware/espressif/esp32/libraries/BLE/src/BLEDevice.cpp line 173 0x400fc0bd: btc_gattc_cb_handler at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c line 31 0x400f805e: btc_task at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/btc/core/btc_task.c line 110 0x40097619: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143

Something I'm doing wrong?

chegewara commented 5 years ago

No, i dont think you are doing something wrong. Just this library is not complete yet and its assuming you have enough free memory to perform this action: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLERemoteCharacteristic.cpp#L192

czuvich commented 5 years ago

Got it. I get that error on the first run. I'm running the WROVER module and it's reporting plenty of heap and uxTaskGetStackHighWaterMark(NULL) has plenty of stack (almost 5K). It almost feels like there's missing test cases against the WROVER modules with SPI RAM.

I went back to using the initial 1.0 production release, and the error went away. I then tried a patched BLE library with the production 1.0 release, and I got the following exception:

10:26:47.222 -> E (17305) boot: Assert failed in heap_caps_free, /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/heap_caps.c:261 (heap != NULL && "free() target pointer is outside heap areas")

Likely the same problem. There's definitely something going on with the BLE library.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This stale issue has been automatically closed. Thank you for your contributions.