Bledroid BLE Init/Deinit memory leak issue

ankitmcgill
Posts: 2
Joined: Wed Nov 13, 2019 8:03 pm

Bledroid BLE Init/Deinit memory leak issue

Postby ankitmcgill » Sun Aug 21, 2022 6:58 am

Hi All,

In my application, I am periodically enabling / disabling ble (bluedroid). I have noticed that with each init / denit cycle, almost 700 bytes of heap memory is leaking. I did find serveral posts regarding this issue on the forum and on the net, but no conclusive solution.

Code: Select all

I (1257) TEST_MEM_LEAK: BEFORE :  216208 
D (1257) intr_alloc: Connected src -5 to int 29 (cpu 0)
D (1267) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
D (1277) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
D (1277) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
D (1287) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
D (1297) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
D (1297) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
D (1307) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
D (1317) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
D (1327) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
D (1327) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
D (1337) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
D (1347) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
D (1347) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
D (1357) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
D (1377) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 8 bit
D (1377) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 0 bit
D (1377) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 24 bit
D (1387) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 16 bit
D (1397) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 8 bit
D (1397) efuse: In EFUSE_BLK0__DATA1_REG is used 8 bits starting with 0 bit
D (1407) efuse: In EFUSE_BLK0__DATA2_REG is used 8 bits starting with 16 bit
I (2257) TEST_MEM_LEAK: AFTER START :  190460 
I (9257) TEST_MEM_LEAK: AFTER STOP :  228924
I (9257) TEST_MEM_LEAK: -----------------------------------------
I (9257) TEST_MEM_LEAK: BEFORE :  228924 
I (10257) TEST_MEM_LEAK: AFTER START :  189696 
I (17257) TEST_MEM_LEAK: AFTER STOP :  228160
I (17257) TEST_MEM_LEAK: -----------------------------------------
I (17257) TEST_MEM_LEAK: BEFORE :  228160 
I (18257) TEST_MEM_LEAK: AFTER START :  188932 
I (25257) TEST_MEM_LEAK: AFTER STOP :  227396
I (25257) TEST_MEM_LEAK: -----------------------------------------
I (25257) TEST_MEM_LEAK: BEFORE :  227396 
I (26257) TEST_MEM_LEAK: AFTER START :  188168 
I (33257) TEST_MEM_LEAK: AFTER STOP :  226632
I (33257) TEST_MEM_LEAK: -----------------------------------------
I (33257) TEST_MEM_LEAK: BEFORE :  226632 
I (34257) TEST_MEM_LEAK: AFTER START :  187404 
I (41257) TEST_MEM_LEAK: AFTER STOP :  225868
I (41257) TEST_MEM_LEAK: -----------------------------------------
I (41257) TEST_MEM_LEAK: BEFORE :  225868 
I (42257) TEST_MEM_LEAK: AFTER START :  186640 
I (49257) TEST_MEM_LEAK: AFTER STOP :  225104
I (49257) TEST_MEM_LEAK: -----------------------------------------
I (49257) TEST_MEM_LEAK: BEFORE :  225104 
I (50257) TEST_MEM_LEAK: AFTER START :  185876 
I (57257) TEST_MEM_LEAK: AFTER STOP :  224340
I (57257) TEST_MEM_LEAK: -----------------------------------------
I (57257) TEST_MEM_LEAK: BEFORE :  224340 
I (58257) TEST_MEM_LEAK: AFTER START :  185112 
I (65257) TEST_MEM_LEAK: AFTER STOP :  223576
I (65257) TEST_MEM_LEAK: -----------------------------------------
I (65257) TEST_MEM_LEAK: BEFORE :  223576 
I (66257) TEST_MEM_LEAK: AFTER START :  184348 
I (73257) TEST_MEM_LEAK: AFTER STOP :  222812
I (73257) TEST_MEM_LEAK: -----------------------------------------
I (73257) TEST_MEM_LEAK: BEFORE :  222812 
I (74257) TEST_MEM_LEAK: AFTER START :  183584 
I (81257) TEST_MEM_LEAK: AFTER STOP :  222048
I (81257) TEST_MEM_LEAK: -----------------------------------------
I (81257) TEST_MEM_LEAK: BEFORE :  222048 
I (82257) TEST_MEM_LEAK: AFTER START :  182820 
I (89257) TEST_MEM_LEAK: AFTER STOP :  221284
I (89257) TEST_MEM_LEAK: -----------------------------------------
I (89257) TEST_MEM_LEAK: BEFORE :  221284 
I (90257) TEST_MEM_LEAK: AFTER START :  182056 
I (97257) TEST_MEM_LEAK: AFTER STOP :  220520
I (97257) TEST_MEM_LEAK: -----------------------------------------
I (97257) TEST_MEM_LEAK: BEFORE :  220520 
I (98257) TEST_MEM_LEAK: AFTER START :  181292 
I (105257) TEST_MEM_LEAK: AFTER STOP :  219756
I (105257) TEST_MEM_LEAK: -----------------------------------------
I (105257) TEST_MEM_LEAK: BEFORE :  219756 
I (106257) TEST_MEM_LEAK: AFTER START :  180528 
I (113257) TEST_MEM_LEAK: AFTER STOP :  218992
I (113257) TEST_MEM_LEAK: -----------------------------------------
I (113257) TEST_MEM_LEAK: BEFORE :  218992 
I (114257) TEST_MEM_LEAK: AFTER START :  179764 
I (121257) TEST_MEM_LEAK: AFTER STOP :  218228
I (121257) TEST_MEM_LEAK: -----------------------------------------
I (121257) TEST_MEM_LEAK: BEFORE :  218228 
I (122257) TEST_MEM_LEAK: AFTER START :  179000 
I (129257) TEST_MEM_LEAK: AFTER STOP :  217464
I (129257) TEST_MEM_LEAK: -----------------------------------------
I (129257) TEST_MEM_LEAK: BEFORE :  217464 
I (130257) TEST_MEM_LEAK: AFTER START :  178236 
I (137257) TEST_MEM_LEAK: AFTER STOP :  216700
I (137257) TEST_MEM_LEAK: -----------------------------------------
I (137257) TEST_MEM_LEAK: BEFORE :  216700 
I (138257) TEST_MEM_LEAK: AFTER START :  177472 
I (145257) TEST_MEM_LEAK: AFTER STOP :  215936
I (145257) TEST_MEM_LEAK: -----------------------------------------
I (145257) TEST_MEM_LEAK: BEFORE :  215936 
I (146257) TEST_MEM_LEAK: AFTER START :  176708 
I (153257) TEST_MEM_LEAK: AFTER STOP :  215172
I (153257) TEST_MEM_LEAK: -----------------------------------------
I (153257) TEST_MEM_LEAK: BEFORE :  215172 
I (154257) TEST_MEM_LEAK: AFTER START :  175944 
I (161257) TEST_MEM_LEAK: AFTER STOP :  214408
I (161257) TEST_MEM_LEAK: -----------------------------------------
I (161257) TEST_MEM_LEAK: BEFORE :  214408 
I (162257) TEST_MEM_LEAK: AFTER START :  175180 
I (169257) TEST_MEM_LEAK: AFTER STOP :  213644
I (169257) TEST_MEM_LEAK: -----------------------------------------
I (169257) TEST_MEM_LEAK: BEFORE :  213644 
I (170257) TEST_MEM_LEAK: AFTER START :  174416 
I (177257) TEST_MEM_LEAK: AFTER STOP :  212880
I (177257) TEST_MEM_LEAK: -----------------------------------------
I (177257) TEST_MEM_LEAK: BEFORE :  212880 
I (178257) TEST_MEM_LEAK: AFTER START :  173652 
I (185257) TEST_MEM_LEAK: AFTER STOP :  212116
I (185257) TEST_MEM_LEAK: -----------------------------------------
I (185257) TEST_MEM_LEAK: BEFORE :  212116 
I (186257) TEST_MEM_LEAK: AFTER START :  172888 
I (193257) TEST_MEM_LEAK: AFTER STOP :  211352
I (193257) TEST_MEM_LEAK: -----------------------------------------
I (193257) TEST_MEM_LEAK: BEFORE :  211352 
I (194257) TEST_MEM_LEAK: AFTER START :  172124 
I (201257) TEST_MEM_LEAK: AFTER STOP :  210588
I (201257) TEST_MEM_LEAK: -----------------------------------------
I (201257) TEST_MEM_LEAK: BEFORE :  210588 
I (202257) TEST_MEM_LEAK: AFTER START :  171360 
I (209257) TEST_MEM_LEAK: AFTER STOP :  209824
I (209257) TEST_MEM_LEAK: -----------------------------------------
I (209257) TEST_MEM_LEAK: BEFORE :  209824 
I (210257) TEST_MEM_LEAK: AFTER START :  170596
All I am doing in these cycles is initializing ble, running a scan and then denintializing ble

Code: Select all

static void s_start(void)
{
    //Start Ble Driver Stack

    esp_err_t err;
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();

    //Free Up Ble Classic Memory
    err = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);

    if((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK)
    {
        goto start_fail;
    }

    if((err = esp_bt_controller_enable(ESP_BT_MODE_BLE)) != ESP_OK)
    {
        goto start_fail;
    }
    
    if((err = esp_bluedroid_init()) != ESP_OK)
    {
        goto start_fail;
    }

    if((err = esp_bluedroid_enable()) != ESP_OK)
    {
        goto start_fail;
    }

    //Register Ble Gap Cb Function
    if((err = esp_ble_gap_register_callback(s_gap_cb)) != ESP_OK)
    {
        goto start_fail;
    }

    //Register Ble Gattc Cb Function
    if((err = esp_ble_gattc_register_callback(s_gattc_cb)) != ESP_OK)
    {
        goto start_fail;
    }

    //Register Gattc Application Profile
    if((err = esp_ble_gattc_app_register(DRIVER_BLE_APPLICATION_PROFILE_A_ID)) != ESP_OK)
    {
        goto start_fail;
    }

    //Gatt Set Mtu Size
    if((err = esp_ble_gatt_set_local_mtu(BLE_MTU_SIZE_MAX)) != ESP_OK)
    {
        goto start_fail;
    }

    s_set_ready_status_bit(DRIVER_BLE_EB_STATUS_READY);
    ESP_LOGD(DRIVER_BLE_TAG, "Start OK");
    return;
    
    start_fail:
        s_set_ready_status_bit(DRIVER_BLE_EB_STATUS_NOTREADY);
        ESP_LOGD(DRIVER_BLE_TAG, "Start FAIL. %s", esp_err_to_name(err));
}

Code: Select all

static void s_stop(void)
{
    //Stop Ble Driver Stack

    esp_err_t err;

    if((err = esp_bluedroid_disable()) != ESP_OK)
    {
        goto stop_fail;
    }

    if((err = esp_bt_controller_disable()) != ESP_OK)
    {
        goto stop_fail;
    }

    if((err = esp_bluedroid_deinit()) != ESP_OK)
    {
        goto stop_fail;
    }

    if((err = esp_bt_controller_deinit()) != ESP_OK)
    {
        goto stop_fail;
    }

    s_set_ready_status_bit(DRIVER_BLE_EB_STATUS_NOTREADY);
    ESP_LOGD(DRIVER_BLE_TAG, "Stop OK");
    return;
    
    stop_fail:
        s_set_ready_status_bit(DRIVER_BLE_EB_STATUS_READY);
        ESP_LOGD(DRIVER_BLE_TAG, "Stop FAIL. %s", esp_err_to_name(err));
}

masterq
Posts: 3
Joined: Fri Feb 23, 2024 8:19 am

Re: Bledroid BLE Init/Deinit memory leak issue

Postby masterq » Fri Feb 23, 2024 8:22 am

Yes have the same problem, did really search long for the leak as I expected it somewhere else...
Did you find a solution?

Best regards

masterq
Posts: 3
Joined: Fri Feb 23, 2024 8:19 am

Re: Bledroid BLE Init/Deinit memory leak issue

Postby masterq » Fri Feb 23, 2024 8:48 am

I did an incomplete analysis of this...

im looping:

Code: Select all

while(true)
{
	heap_trace_start(HEAP_TRACE_LEAKS);
	
	esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
	esp_bt_controller_init(&bt_cfg);
	esp_bt_controller_enable(ESP_BT_MODE_BTDM);
	esp_bluedroid_init();
	esp_bluedroid_enable();

	esp_bluedroid_disable();
	esp_bluedroid_deinit();
	esp_bt_controller_disable();
	esp_bt_controller_deinit();
	
	heap_trace_stop();
	heap_trace_dump();
}
And get this incomplete result:

Code: Select all

15 allocations trace (200 entry buffer)
4864 bytes (@ 0x3fffa920) allocated CPU 0 ccount 0xccd081f8 caller 0x401fe126:0x4011da21:0x400fbf23:0x400e8b23:0x400e33a0
0x401fe126: xTaskCreatePinnedToCore at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/tasks.c:868

0x4011da21: osi_thread_create at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/thread.c:253

0x400fbf23: BTU_StartUp at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_init.c:187

0x400e8b23: bte_main_boot_entry at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/main/bte_main.c:92

0x400e33a0: btc_init_bluetooth at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/btc/core/btc_main.c:58
 (inlined by) btc_main_call_handler at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/btc/core/btc_main.c:103

356 bytes (@ 0x3ffee4ec) allocated CPU 0 ccount 0xccd0a110 caller 0x401fe13c:0x4011da21:0x400fbf23:0x400e8b23:0x400e33a0
0x401fe13c: xTaskCreatePinnedToCore at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/tasks.c:873

0x4011da21: osi_thread_create at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/thread.c:253

0x400fbf23: BTU_StartUp at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_init.c:187

0x400e8b23: bte_main_boot_entry at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/main/bte_main.c:92

0x400e33a0: btc_init_bluetooth at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/btc/core/btc_main.c:58
 (inlined by) btc_main_call_handler at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/btc/core/btc_main.c:103

24 bytes (@ 0x3ffeeca0) allocated CPU 0 ccount 0xccd37000 caller 0x4011c9f6:0x400f59cd:0x400f4f72:0x400fbe06:0x400fc15e
0x4011c9f6: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:39

0x400f59cd: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:116

0x400f4f72: btm_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_main.c:83

0x400fbe06: btu_init_core at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_init.c:94

0x400fc15e: btu_task_start_up at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_task.c:273

92 bytes (@ 0x3ffeecc8) allocated CPU 0 ccount 0xccd38d9c caller 0x401fce1c:0x401fcd77:0x4011d748:0x4011ca11:0x400f59cd
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x401fcd77: xQueueCreateMutex at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:564

0x4011d748: osi_mutex_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/mutex.c:35

0x4011ca11: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:48

0x400f59cd: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:116

16 bytes (@ 0x3ffeed34) allocated CPU 0 ccount 0xccd3b808 caller 0x4011d1f9:0x4011ca18:0x400f59cd:0x400f4f72:0x400fbe06
0x4011d1f9: list_new_internal at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/list.c:26
 (inlined by) list_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/list.c:38

0x4011ca18: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:48

0x400f59cd: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:116

0x400f4f72: btm_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_main.c:83

0x400fbe06: btu_init_core at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_init.c:94

92 bytes (@ 0x3ffeed54) allocated CPU 0 ccount 0xccd3d568 caller 0x401fce1c:0x401fcd15:0x4011dcec:0x4011ca27:0x400f59cd
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x401fcd15: xQueueCreateCountingSemaphore at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:792

0x4011dcec: osi_sem_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/semaphore.c:32

0x4011ca27: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:55

0x400f59cd: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:116

92 bytes (@ 0x3ffeedc0) allocated CPU 0 ccount 0xccd3f4dc caller 0x401fce1c:0x401fcd15:0x4011dcec:0x4011ca35:0x400f59cd
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x401fcd15: xQueueCreateCountingSemaphore at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:792

0x4011dcec: osi_sem_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/semaphore.c:32

0x4011ca35: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:60

0x400f59cd: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:116

24 bytes (@ 0x3ffeee2c) allocated CPU 0 ccount 0xccd41568 caller 0x4011c9f6:0x400f59dc:0x400f4f72:0x400fbe06:0x400fc15e
0x4011c9f6: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:39

0x400f59dc: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:122

0x400f4f72: btm_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_main.c:83

0x400fbe06: btu_init_core at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_init.c:94

0x400fc15e: btu_task_start_up at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_task.c:273

92 bytes (@ 0x3ffeee54) allocated CPU 0 ccount 0xccd432ec caller 0x401fce1c:0x401fcd77:0x4011d748:0x4011ca11:0x400f59dc
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x401fcd77: xQueueCreateMutex at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:564

0x4011d748: osi_mutex_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/mutex.c:35

0x4011ca11: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:48

0x400f59dc: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:122

16 bytes (@ 0x3ffeeec0) allocated CPU 0 ccount 0xccd45484 caller 0x4011d1f9:0x4011ca18:0x400f59dc:0x400f4f72:0x400fbe06
0x4011d1f9: list_new_internal at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/list.c:26
 (inlined by) list_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/list.c:38

0x4011ca18: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:48

0x400f59dc: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:122

0x400f4f72: btm_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_main.c:83

0x400fbe06: btu_init_core at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btu/btu_init.c:94

92 bytes (@ 0x3ffeeee0) allocated CPU 0 ccount 0xccd471e4 caller 0x401fce1c:0x401fcd15:0x4011dcec:0x4011ca27:0x400f59dc
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x401fcd15: xQueueCreateCountingSemaphore at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:792

0x4011dcec: osi_sem_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/semaphore.c:32

0x4011ca27: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:55

0x400f59dc: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:122

92 bytes (@ 0x3ffeef4c) allocated CPU 0 ccount 0xccd49158 caller 0x401fce1c:0x401fcd15:0x4011dcec:0x4011ca35:0x400f59dc
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x401fcd15: xQueueCreateCountingSemaphore at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:792

0x4011dcec: osi_sem_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/semaphore.c:32

0x4011ca35: fixed_queue_new at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/common/osi/fixed_queue.c:60

0x400f59dc: btm_sco_init at /opt/htv-apps/espressif-4.4/esp-idf/components/bt/host/bluedroid/stack/btm/btm_sco.c:122

92 bytes (@ 0x3fff0410) allocated CPU 0 ccount 0xdd5135a8 caller 0x401fce1c:0x4018adea:0x4018ae3a:0x4018ba8e:0x4018bfe8
0x401fce1c: xQueueGenericCreate at /opt/htv-apps/espressif-4.4/esp-idf/components/freertos/queue.c:447

0x4018adea: sys_thread_sem_init at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:537

0x4018ae3a: sys_thread_sem_get at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:509

0x4018ba8e: netconn_apimsg at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/lwip/src/api/api_lib.c:133

0x4018bfe8: netconn_send at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/lwip/src/api/api_lib.c:966 (discriminator 2)

4 bytes (@ 0x3fff047c) allocated CPU 0 ccount 0xdd516520 caller 0x400d3614:0x4018ae22:0x4018ae3a:0x4018ba8e:0x4018bfe8
0x400d3614: pthread_setspecific at /opt/htv-apps/espressif-4.4/esp-idf/components/pthread/pthread_local_storage.c:230

0x4018ae22: sys_thread_sem_init at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:546

0x4018ae3a: sys_thread_sem_get at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:509

0x4018ba8e: netconn_apimsg at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/lwip/src/api/api_lib.c:133

0x4018bfe8: netconn_send at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/lwip/src/api/api_lib.c:966 (discriminator 2)

12 bytes (@ 0x3fffd2e0) allocated CPU 0 ccount 0xdd51892c caller 0x400d3673:0x4018ae22:0x4018ae3a:0x4018ba8e:0x4018bfe8
0x400d3673: pthread_setspecific at /opt/htv-apps/espressif-4.4/esp-idf/components/pthread/pthread_local_storage.c:256

0x4018ae22: sys_thread_sem_init at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:546

0x4018ae3a: sys_thread_sem_get at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c:509

0x4018ba8e: netconn_apimsg at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/lwip/src/api/api_lib.c:133

0x4018bfe8: netconn_send at /opt/htv-apps/espressif-4.4/esp-idf/components/lwip/lwip/src/api/api_lib.c:966 (discriminator 2)

5960 bytes 'leaked' in trace (15 allocations)
total allocations 595 total frees 659
(NB: Buffer has overflowed, so trace data is incomplete.)
W (105405) bPipe: ############# Reenable: 34, ram: 4204535 intram: 50220
I'm not loosing 5960 bytes but 700 bytes up to 1KiByte every iteration.

I have problems with posting my complete sdkconfig, as it can contain passwords. But here is a part:

Code: Select all

cat sdkconfig|egrep -i "bt|ble"|grep -v "is not set"

Code: Select all

CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE=y
CONFIG_BOOTLOADER_WDT_ENABLE=y
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
# Partition Table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="bareco_partitions_ota.csv"
CONFIG_PARTITION_TABLE_FILENAME="bareco_partitions_ota.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
CONFIG_APPTRACE_LOCK_ENABLE=y
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BTDM=y
CONFIG_BTDM_CTRL_BLE_MAX_CONN=2
CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN=2
CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN=0
CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_PCM=y
CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=1
CONFIG_BTDM_CTRL_PCM_ROLE_EDGE_CONFIG=y
CONFIG_BTDM_CTRL_PCM_ROLE_MASTER=y
CONFIG_BTDM_CTRL_PCM_POLAR_FALLING_EDGE=y
CONFIG_BTDM_CTRL_PCM_ROLE_EFF=0
CONFIG_BTDM_CTRL_PCM_POLAR_EFF=0
CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT=y
CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF=y
CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=2
CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF=2
CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0
CONFIG_BTDM_CTRL_PINNED_TO_CORE_0=y
CONFIG_BTDM_CTRL_PINNED_TO_CORE=0
CONFIG_BTDM_CTRL_HCI_MODE_VHCI=y
CONFIG_BTDM_CTRL_MODEM_SLEEP=y
CONFIG_BTDM_CTRL_MODEM_SLEEP_MODE_ORIG=y
CONFIG_BTDM_CTRL_LPCLK_SEL_MAIN_XTAL=y
CONFIG_BTDM_BLE_DEFAULT_SCA_250PPM=y
CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF=1
CONFIG_BTDM_BLE_SCAN_DUPL=y
CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE=y
CONFIG_BTDM_SCAN_DUPL_TYPE=0
CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=100
CONFIG_BTDM_SCAN_DUPL_CACHE_REFRESH_PERIOD=0
CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED=y
CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
CONFIG_BTDM_RESERVE_DRAM=0xdb5c
CONFIG_BTDM_CTRL_HLI=y
CONFIG_BT_BLUEDROID_ENABLED=y
CONFIG_BT_BTC_TASK_STACK_SIZE=2500
CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0=y
CONFIG_BT_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BT_BTU_TASK_STACK_SIZE=4352
CONFIG_BT_CLASSIC_ENABLED=y
CONFIG_BT_A2DP_ENABLE=y
CONFIG_BT_HFP_ENABLE=y
CONFIG_BT_HFP_CLIENT_ENABLE=y
CONFIG_BT_HFP_AG_ENABLE=y
CONFIG_BT_HFP_AUDIO_DATA_PATH_HCI=y
CONFIG_BT_HFP_WBS_ENABLE=y
CONFIG_BT_SSP_ENABLED=y
CONFIG_BT_BLE_ENABLED=y
CONFIG_BT_GATTS_ENABLE=y
CONFIG_BT_GATT_MAX_SR_PROFILES=4
CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=50
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO=y
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
CONFIG_BT_GATTC_ENABLE=y
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
CONFIG_BT_GATTC_NOTIF_REG_MAX=5
CONFIG_BT_GATTC_CONNECT_RETRY_COUNT=3
CONFIG_BT_BLE_SMP_ENABLE=y
# BT DEBUG LOG LEVEL
CONFIG_BT_LOG_HCI_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_HCI_TRACE_LEVEL=2
CONFIG_BT_LOG_BTM_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BTM_TRACE_LEVEL=2
CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_L2CAP_TRACE_LEVEL=2
CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL=2
CONFIG_BT_LOG_SDP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_SDP_TRACE_LEVEL=2
CONFIG_BT_LOG_GAP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_GAP_TRACE_LEVEL=2
CONFIG_BT_LOG_BNEP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BNEP_TRACE_LEVEL=2
CONFIG_BT_LOG_PAN_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_PAN_TRACE_LEVEL=2
CONFIG_BT_LOG_A2D_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_A2D_TRACE_LEVEL=2
CONFIG_BT_LOG_AVDT_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_AVDT_TRACE_LEVEL=2
CONFIG_BT_LOG_AVCT_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_AVCT_TRACE_LEVEL=2
CONFIG_BT_LOG_AVRC_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_AVRC_TRACE_LEVEL=2
CONFIG_BT_LOG_MCA_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_MCA_TRACE_LEVEL=2
CONFIG_BT_LOG_HID_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_HID_TRACE_LEVEL=2
CONFIG_BT_LOG_APPL_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_APPL_TRACE_LEVEL=2
CONFIG_BT_LOG_GATT_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_GATT_TRACE_LEVEL=2
CONFIG_BT_LOG_SMP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_SMP_TRACE_LEVEL=2
CONFIG_BT_LOG_BTIF_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BTIF_TRACE_LEVEL=2
CONFIG_BT_LOG_BTC_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BTC_TRACE_LEVEL=2
CONFIG_BT_LOG_OSI_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_OSI_TRACE_LEVEL=2
CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2
# end of BT DEBUG LOG LEVEL
CONFIG_BT_ACL_CONNECTIONS=2
CONFIG_BT_MULTI_CONNECTION_ENBALE=y
CONFIG_BT_SMP_ENABLE=y
CONFIG_BT_SMP_MAX_BONDS=4
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
CONFIG_BT_BLE_RPA_TIMEOUT=900
CONFIG_ADC_DISABLE_DAC=y
CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y
CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y
CONFIG_ADC_CAL_LUT_ENABLE=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y
CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y
CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS=y
CONFIG_ESP_IPC_ISR_ENABLE=y
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=y
CONFIG_ESP32_WIFI_ENABLED=y
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y
CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y
CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
CONFIG_MBEDTLS_TLS_ENABLED=y
CONFIG_MBEDTLS_RC4_DISABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=y
CONFIG_HTV_MODULE_WEBSERVER_ENABLED=y
CONFIG_HTV_WEBFLASH_ENABLED=y
CONFIG_APP_ROLLBACK_ENABLE=y
CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
CONFIG_BTDM_CONTROLLER_MODE_BTDM=y
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN=0
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y
CONFIG_BLE_SCAN_DUPLICATE=y
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100
CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
CONFIG_BLUEDROID_ENABLED=y
CONFIG_BTC_TASK_STACK_SIZE=2500
CONFIG_BTU_TASK_STACK_SIZE=4352
CONFIG_CLASSIC_BT_ENABLED=y
CONFIG_A2DP_ENABLE=y
CONFIG_HFP_ENABLE=y
CONFIG_HFP_CLIENT_ENABLE=y
CONFIG_HFP_AG_ENABLE=y
CONFIG_GATTS_ENABLE=y
CONFIG_GATTC_ENABLE=y
CONFIG_BLE_SMP_ENABLE=y
CONFIG_BTM_TRACE_LEVEL_WARNING=y
CONFIG_BTM_INITIAL_TRACE_LEVEL=2
CONFIG_BTH_LOG_SDP_INITIAL_TRACE_LEVEL=2
CONFIG_BTIF_TRACE_LEVEL_WARNING=y
CONFIG_BTIF_INITIAL_TRACE_LEVEL=2
CONFIG_BTC_TRACE_LEVEL_WARNING=y
CONFIG_BTC_INITIAL_TRACE_LEVEL=2
CONFIG_SMP_ENABLE=y
CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
CONFIG_ADC2_DISABLE_DAC=y
CONFIG_SW_COEXIST_ENABLE=y
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
I hope this helps to help :)

Best Regards

masterq
Posts: 3
Joined: Fri Feb 23, 2024 8:19 am

Re: Bledroid BLE Init/Deinit memory leak issue

Postby masterq » Fri Feb 23, 2024 9:38 am

Ok, I found something. The memory leak only happens if:
BTDM_CTRL_BR_EDR_SCO_DATA_PATH_HCI
BT_HFP_AUDIO_DATA_PATH_HCI

If both options are set the leak appears always. I think there was a special case where the leak did not appear with one of the options enabled. But with both enabled it always appears and with both disabled never.

However, this should help to find the leak.

Users can try to use PCM to avoid the leak.

Regards

Who is online

Users browsing this forum: No registered users and 84 guests