Skip to content

Memory leak on BLEDevice::init() and deinit() #928

Closed
@arthurkafer

Description

@arthurkafer

Using ESP-WROOM-32U, running a simple code to simulate init and deinit of a BLEDevice.

Compile settings:

  • Board: ESP32 Dev Module;
  • Upload Speed: 921600;
  • Flash Frequency: 80MHz;
  • Flash Mode: QIO;
  • Partition Scheme: Default;
  • Core Debug Level: Verbose;
  • PSRAM: Disabled;
#include <BLEDevice.h>

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
    BLEDevice::init("testeaqi");
}

void loop() {
    Serial.println(ESP.getFreeHeap());
    if (BLEDevice::getInitialized() == true){
        Serial.println("BLE_OFF()");
        BLEDevice::deinit(false);
    }
    else {
        Serial.println("NEW_INIT()");
        BLEDevice::init("testeasd");
    }
}

Here are the logs:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9296
load:0x40080400,len:6364
entry 0x400806a4
184740
BLE_OFF()
268236
NEW_INIT()
181468
BLE_OFF()
264960
NEW_INIT()
178180
BLE_OFF()
261536
NEW_INIT()
174760
BLE_OFF()
258248
NEW_INIT()
171476
BLE_OFF()
254828
NEW_INIT()
168072
BLE_OFF()
251552
NEW_INIT()
164800
BLE_OFF()
248424
NEW_INIT()
161664
BLE_OFF()
245152
NEW_INIT()
158400
BLE_OFF()
241880
NEW_INIT()
155116
BLE_OFF()
238460
NEW_INIT()
151712
BLE_OFF()
235332
NEW_INIT()
148584
BLE_OFF()
231912
NEW_INIT()
145164
BLE_OFF()
228636
NEW_INIT()
141912
BLE_OFF()
225368
NEW_INIT()
138756
BLE_OFF()
222244
NEW_INIT()
135484
BLE_OFF()
218972
NEW_INIT()
132216
BLE_OFF()
220036
NEW_INIT()
128844
BLE_OFF()
212428
NEW_INIT()
125664
BLE_OFF()
209156
NEW_INIT()
122276
BLE_OFF()
205736
NEW_INIT()
119008
BLE_OFF()
202464
NEW_INIT()
115736
BLE_OFF()
199336
NEW_INIT()
112584
BLE_OFF()
196060
NEW_INIT()
109300
BLE_OFF()
192788
NEW_INIT()
105884
BLE_OFF()
193476
NEW_INIT()
102752
BLE_OFF()
186240
NEW_INIT()
99504
BLE_OFF()
182820
NEW_INIT()
96092
BLE_OFF()
179548
NEW_INIT()
92820
BLE_OFF()
176424
NEW_INIT()
89680
BLE_OFF()
173152
NEW_INIT()
86412
BLE_OFF()
169880
NEW_INIT()
83136
BLE_OFF()
166460
NEW_INIT()
79720
BLE_OFF()
163332
NEW_INIT()
76588
BLE_OFF()
159916
NEW_INIT()
73164
BLE_OFF()
161128
NEW_INIT()
69888
BLE_OFF()
153372
NEW_INIT()
66756
BLE_OFF()
150240
NEW_INIT()
63476
BLE_OFF()
146968
NEW_INIT()
60204
BLE_OFF()
148036
NEW_INIT()
56800
BLE_OFF()
140424
NEW_INIT()
53536
BLE_OFF()
137152
NEW_INIT()
Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c46c  PS      : 0x00060b30  A0      : 0x8011ab82  A1      : 0x3ffd7d30  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x0000001c  A5      : 0x00000000  
A6      : 0x4018844c  A7      : 0x00000001  A8      : 0x800dc11e  A9      : 0x3ffd7cd0  
A10     : 0x3ffe3e60  A11     : 0x00000044  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x00001800  A15     : 0x00000084  SAR     : 0x0000001e  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  

Backtrace: 0x4000c46c:0x3ffd7d30 0x4011ab7f:0x3ffd7d40 0x4011b455:0x3ffd7d60 0x400f6279:0x3ffd7d80 0x400f62b3:0x3ffd7da0 0x40092da5:0x3ffd7dd0

Rebooting...

The backtrace results in this:

0x4011ab7f: bta_ar_init at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/bta/ar/bta_ar.c line 72

Decoding stack results
0x4011b455: bta_sys_init at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/bta/sys/bta_sys_main.c line 186
0x400f6279: btu_task_start_up at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/stack/btu/btu_task.c line 284
0x400f62b3: btu_task_thread_handler at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/stack/btu/btu_task.c line 226
0x40092da5: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143
0x4011ab7f: bta_ar_init at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/bta/ar/bta_ar.c line 72
0x4011b455: bta_sys_init at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/bta/sys/bta_sys_main.c line 186
0x400f6279: btu_task_start_up at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/stack/btu/btu_task.c line 284
0x400f62b3: btu_task_thread_handler at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/bt/bluedroid/stack/btu/btu_task.c line 226
0x40092da5: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143

Every single iteration of the init/deinit loop is leaking ~4k, and I could'nt find any other way to fix this. My initial problem is based on this memory leak, I think you could help me with this.

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions