NimBLE memory leak?

davdav
Posts: 206
Joined: Thu Nov 17, 2016 2:33 pm

NimBLE memory leak?

Postby davdav » Tue Feb 16, 2021 3:55 pm

Hi everybody,

I'm trying to port our application which used Bluedroid to nimBLE. I'm working with esp-idf-v4.2.

In my opinion there is a memory leak when nimble is init and deinit if GAP advertizing is used.

I have written a simple code to test it (derived from "bleprph" example). Please find attached the code and my sdkconfig (renamed to .txt to be able to attach).

The test is simple. At start-up nimble is init and esp32 start advertizing.
After 30 seconds advertizing is stopped and nimBLE deinit.
After 30 seconds nimble is init and start advertizing and so on...
Program is working as expected and I can monitor using a "beacon scanner" APP that advertiziing start/stop correctly.

Everytime I init and deinit nimBLE, I print the available heap using function "esp_get_free_heap_size" and as you can see it decreases of 48 bytes each time it is init/deinit.

Code: Select all

W (311) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:240496
W (640) NimBLE_BLE_PRPH: BLE Host Task Started
W (29648) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226452
W (29651) NimBLE_BLE_PRPH: DeINIT BLE OK
W (59651) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254984
W (59911) NimBLE_BLE_PRPH: BLE Host Task Started
W (89918) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226396
W (89921) NimBLE_BLE_PRPH: DeINIT BLE OK
W (119921) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254932
W (120171) NimBLE_BLE_PRPH: BLE Host Task Started
W (150178) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226344
W (150181) NimBLE_BLE_PRPH: DeINIT BLE OK
W (180181) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254884
W (180434) NimBLE_BLE_PRPH: BLE Host Task Started
W (210441) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226296
W (210444) NimBLE_BLE_PRPH: DeINIT BLE OK
W (240444) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254836
W (240694) NimBLE_BLE_PRPH: BLE Host Task Started
W (270702) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226248
W (270705) NimBLE_BLE_PRPH: DeINIT BLE OK
W (300705) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254788
W (300965) NimBLE_BLE_PRPH: BLE Host Task Started
W (330972) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226200
W (330975) NimBLE_BLE_PRPH: DeINIT BLE OK
W (360975) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254740
W (361223) NimBLE_BLE_PRPH: BLE Host Task Started
W (391230) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226152
W (391233) NimBLE_BLE_PRPH: DeINIT BLE OK
W (421233) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254692
W (421498) NimBLE_BLE_PRPH: BLE Host Task Started
W (451506) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226104
W (451509) NimBLE_BLE_PRPH: DeINIT BLE OK
W (481509) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254644
W (481772) NimBLE_BLE_PRPH: BLE Host Task Started
W (511779) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226056
W (511782) NimBLE_BLE_PRPH: DeINIT BLE OK
W (541782) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254596
W (542036) NimBLE_BLE_PRPH: BLE Host Task Started
W (572044) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:226008
W (572047) NimBLE_BLE_PRPH: DeINIT BLE OK
W (602047) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254548
W (602306) NimBLE_BLE_PRPH: BLE Host Task Started
W (632313) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225960
W (632316) NimBLE_BLE_PRPH: DeINIT BLE OK
W (662316) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254500
W (662564) NimBLE_BLE_PRPH: BLE Host Task Started
W (692571) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225912
W (692574) NimBLE_BLE_PRPH: DeINIT BLE OK
W (722574) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254452
W (722828) NimBLE_BLE_PRPH: BLE Host Task Started
W (752835) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225868
W (752838) NimBLE_BLE_PRPH: DeINIT BLE OK
W (782838) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254404
W (783091) NimBLE_BLE_PRPH: BLE Host Task Started
W (813098) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225816
W (813101) NimBLE_BLE_PRPH: DeINIT BLE OK
W (843101) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254356
W (843356) NimBLE_BLE_PRPH: BLE Host Task Started
W (873363) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225768
W (873366) NimBLE_BLE_PRPH: DeINIT BLE OK
W (903366) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254308
W (903618) NimBLE_BLE_PRPH: BLE Host Task Started
W (933625) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225720
W (933628) NimBLE_BLE_PRPH: DeINIT BLE OK
W (963628) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254260
W (963882) NimBLE_BLE_PRPH: BLE Host Task Started
W (993889) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225672
W (993892) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1023892) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254212
W (1024148) NimBLE_BLE_PRPH: BLE Host Task Started
W (1054155) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225624
W (1054158) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1084158) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254164
W (1084411) NimBLE_BLE_PRPH: BLE Host Task Started
W (1114418) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225572
W (1114421) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1144421) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254112
W (1144677) NimBLE_BLE_PRPH: BLE Host Task Started
W (1174684) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225524
W (1174687) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1204687) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254064
W (1204953) NimBLE_BLE_PRPH: BLE Host Task Started
W (1234960) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225476
W (1234963) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1264963) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:254016
W (1265217) NimBLE_BLE_PRPH: BLE Host Task Started
W (1295225) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225432
W (1295228) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1325228) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:253968
W (1325480) NimBLE_BLE_PRPH: BLE Host Task Started
W (1355487) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225384
W (1355490) NimBLE_BLE_PRPH: DeINIT BLE OK
W (1385490) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:253920
W (1385746) NimBLE_BLE_PRPH: BLE Host Task Started
W (1415753) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:225332
W (1415756) NimBLE_BLE_PRPH: DeINIT BLE OK
I think to have done everything correct.

Thanks
Attachments
sdkconfig.txt
(40.28 KiB) Downloaded 11 times
main.c
(6.63 KiB) Downloaded 22 times

ESP_Minatel
Posts: 95
Joined: Mon Jan 04, 2021 2:06 pm

Re: NimBLE memory leak?

Postby ESP_Minatel » Thu Feb 18, 2021 9:46 am

Hi,


Can you create an issue in our GitHub to report that?

ESP_Hrishi
Posts: 15
Joined: Fri Sep 28, 2018 3:06 am

Re: NimBLE memory leak?

Postby ESP_Hrishi » Fri Feb 19, 2021 6:33 am

@davdav

Thank you for reporting the issue and for providing a simplistic code to recreate the same. Yes, this looks like a problem.
Just to give you some background, the NimBLE upstream does not yet have the stop/deinit support integrated. We have added this functionality to our port (esp-nimble). When it was first added, it was verified that there was no memory leak. This looks like a regression:

The NimBLE upstream software release after that seem to have added a data structure in the stop procedure. We, in our port, need to remove/delete it in the deinit procedure as we support init/deinit multiple times. We will share a patch here for you to verify, when it is done. Thanks!

davdav
Posts: 206
Joined: Thu Nov 17, 2016 2:33 pm

Re: NimBLE memory leak?

Postby davdav » Sun Feb 21, 2021 4:49 pm

ESP_Hrishi wrote:
Fri Feb 19, 2021 6:33 am
@davdav

Thank you for reporting the issue and for providing a simplistic code to recreate the same. Yes, this looks like a problem.
Just to give you some background, the NimBLE upstream does not yet have the stop/deinit support integrated. We have added this functionality to our port (esp-nimble). When it was first added, it was verified that there was no memory leak. This looks like a regression:

The NimBLE upstream software release after that seem to have added a data structure in the stop procedure. We, in our port, need to remove/delete it in the deinit procedure as we support init/deinit multiple times. We will share a patch here for you to verify, when it is done. Thanks!
Hi @ESP_Hrishi,

I remain at your disposal. consider that in my "real application" the leak seems more than 48 byte (about 500bytes) but I didn't shared the code because it is quite complex (and maybe there are programming issues on my side) so I preferred to give a small and repeatable code.

@ESP_Minatel: should I still open issue in github? Or is it already opened in your internal system?

Thanks

ESP_Hrishi
Posts: 15
Joined: Fri Sep 28, 2018 3:06 am

Re: NimBLE memory leak?

Postby ESP_Hrishi » Mon Feb 22, 2021 1:10 pm

@davdav

You don't need to file an issue. It is now tracked internally.

Quick fix: Can you please add the following line (in green) below ble_npl_callout_stop in the file esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs_stop.c:

ble_npl_callout_stop(&ble_hs_stop_terminate_tmo);
ble_npl_callout_deinit(&ble_hs_stop_terminate_tmo);

With this I could see the free heap remaining constant (with your example) for the subsequent init/deinit cycles. Please try it out and let me know if this helps. Once verified, we can review and add it to the mainline.

P.S. This is a single line change and hence I thought to give it directly instead of creating a patch. Thanks!

davdav
Posts: 206
Joined: Thu Nov 17, 2016 2:33 pm

Re: NimBLE memory leak?

Postby davdav » Mon Feb 22, 2021 4:05 pm

ESP_Hrishi wrote:
Mon Feb 22, 2021 1:10 pm
@davdav

You don't need to file an issue. It is now tracked internally.

Quick fix: Can you please add the following line (in green) below ble_npl_callout_stop in the file esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs_stop.c:

ble_npl_callout_stop(&ble_hs_stop_terminate_tmo);
ble_npl_callout_deinit(&ble_hs_stop_terminate_tmo);

With this I could see the free heap remaining constant (with your example) for the subsequent init/deinit cycles. Please try it out and let me know if this helps. Once verified, we can review and add it to the mainline.

P.S. This is a single line change and hence I thought to give it directly instead of creating a patch. Thanks!
Hello @ESP_Hrishi,

I'm sorry but I don't find "ble_npl_callout_stop" in ble_hs_stop.c file.

As mentioned in my original post I'm using esp-idf-v4.2 where esp-nimble has commit 95bd864 (nimble-v1.2.0-idf branch).
Should I update the entire submodule nimble? I have verified that "ble_npl_callout_stop" is present in "nimble-v1.3.0-idf" branch.

Thanks!

ESP_Hrishi
Posts: 15
Joined: Fri Sep 28, 2018 3:06 am

Re: NimBLE memory leak?

Postby ESP_Hrishi » Mon Feb 22, 2021 4:31 pm

@davdav

Sorry for missing this in the first place. I just tried it with latest `release/v4.2` branch (ESP-IDF Github with NimBLE submodule head ba72e37ac40c13b66ad49c3178c0dbc9588add61 from `nimble-1.2.0-idf` branch ) and I am not able to see any issue with your code. Below is a snapshot of the logs (I have just changed the time from 30 and 60 seconds to 5 and 10 seconds respectively)

Code: Select all

W (946) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (4956) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232212
GAP procedure initiated: stop advertising.
W (4956) NimBLE_BLE_PRPH: DeINIT BLE OK
W (9956) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262352
I (9956) BTDM_INIT: BT controller compile version [d886f91]
W (10196) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (15196) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232208 <<<<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (15196) NimBLE_BLE_PRPH: DeINIT BLE OK
W (20196) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262352
I (20196) BTDM_INIT: BT controller compile version [d886f91]
W (20436) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (25436) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232208 <<<<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (25436) NimBLE_BLE_PRPH: DeINIT BLE OK
W (30436) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262352
I (30436) BTDM_INIT: BT controller compile version [d886f91]
W (30686) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (35686) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232208 <<<<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (35686) NimBLE_BLE_PRPH: DeINIT BLE OK
W (40686) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262352
I (40686) BTDM_INIT: BT controller compile version [d886f91]
W (40936) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (45936) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232208 <<<<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (45936) NimBLE_BLE_PRPH: DeINIT BLE OK
W (50936) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262352
I (50936) BTDM_INIT: BT controller compile version [d886f91]
W (51196) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0

Please let me know if I am missing anything.

davdav
Posts: 206
Joined: Thu Nov 17, 2016 2:33 pm

Re: NimBLE memory leak?

Postby davdav » Mon Feb 22, 2021 5:05 pm

Hello @ESP_Hrishi,

I'm on TAG" v4.2" (https://github.com/espressif/esp-idf/tree/v4.2/) not branch "release/v4.2":

I guess the correct way is to use the TAG which is associated to stable and "verified" version.

Anyway I will try to update submodule "nimble" to the commit you specifed.


Thanks!

ESP_Hrishi
Posts: 15
Joined: Fri Sep 28, 2018 3:06 am

Re: NimBLE memory leak?

Postby ESP_Hrishi » Mon Feb 22, 2021 5:27 pm

The same works fine on v4.2 release as well (ESP-IDF Github head: c40f2590bf759ff60ef122afa79b4ec04e7633d2 esp-nimble head: 95bd8644abf4a410dd3fb914468d3a23ac9bbec2 nimble-1.2.0-idf branch) Logs:

Code: Select all

I (30) boot: ESP-IDF v4.2 2nd stage bootloader
I (30) boot: compile time 22:39:39
I (30) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0c008 ( 49160) map
I (132) esp_image: segment 1: paddr=0x0001c030 vaddr=0x3ffbdb60 size=0x033d8 ( 13272) load
I (137) esp_image: segment 2: paddr=0x0001f410 vaddr=0x40080000 size=0x00404 (  1028) load
0x40080000: _WindowOverflow4 at /home/hrishi/open_source/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (139) esp_image: segment 3: paddr=0x0001f81c vaddr=0x40080404 size=0x007fc (  2044) load
I (148) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x4fbcc (326604) map
0x400d0020: _stext at ??:?

I (280) esp_image: segment 5: paddr=0x0006fbf4 vaddr=0x40080c00 size=0x146ec ( 83692) load
I (329) boot: Loaded app from partition at offset 0x10000
I (329) boot: Disabling RNG early entropy source...
I (329) cpu_start: Pro cpu up.
I (333) cpu_start: Application information:
I (338) cpu_start: Project name:     bleprph
I (343) cpu_start: App version:      v4.2
I (347) cpu_start: Compile time:     Feb 22 2021 22:39:34
I (354) cpu_start: ELF file SHA256:  8d86bd2e142c604f...
I (360) cpu_start: ESP-IDF:          v4.2
I (364) cpu_start: Starting app cpu, entry point is 0x40081890
0x40081890: call_start_cpu1 at /home/hrishi/open_source/esp-idf/components/esp32/cpu_start.c:287

I (0) cpu_start: App cpu up.
I (375) heap_init: Initializing. RAM available for dynamic allocation:
I (382) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (388) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (394) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (400) heap_init: At 3FFC3800 len 0001C800 (114 KiB): DRAM
I (406) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (412) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (419) heap_init: At 400952EC len 0000AD14 (43 KiB): IRAM
I (425) cpu_start: Pro cpu start user code
I (444) spi_flash: detected chip: gd
I (444) spi_flash: flash io: dio
W (444) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (454) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
W (540) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:246328
I (540) BTDM_INIT: BT controller compile version [3723d5b]
I (540) system_api: Base MAC address is not set
I (540) system_api: read default base MAC address from EFUSE
I (640) phy: phy_version: 4500, 0cd6843, Sep 17 2020, 15:37:07, 0, 0
W (870) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (4870) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232264
GAP procedure initiated: stop advertising.
W (4870) NimBLE_BLE_PRPH: DeINIT BLE OK
W (9870) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (9870) BTDM_INIT: BT controller compile version [3723d5b]
W (10120) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (15120) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (15120) NimBLE_BLE_PRPH: DeINIT BLE OK
W (20120) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (20120) BTDM_INIT: BT controller compile version [3723d5b]
W (20350) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (25350) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (25350) NimBLE_BLE_PRPH: DeINIT BLE OK
W (30350) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (30350) BTDM_INIT: BT controller compile version [3723d5b]
W (30590) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (35590) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (35590) NimBLE_BLE_PRPH: DeINIT BLE OK
W (40590) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (40590) BTDM_INIT: BT controller compile version [3723d5b]
W (40830) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (45840) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (45840) NimBLE_BLE_PRPH: DeINIT BLE OK
W (50840) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (50840) BTDM_INIT: BT controller compile version [3723d5b]
W (51090) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0

Can you please check once?

davdav
Posts: 206
Joined: Thu Nov 17, 2016 2:33 pm

Re: NimBLE memory leak?

Postby davdav » Tue Feb 23, 2021 7:59 am

ESP_Hrishi wrote:
Mon Feb 22, 2021 5:27 pm
The same works fine on v4.2 release as well (ESP-IDF Github head: c40f2590bf759ff60ef122afa79b4ec04e7633d2 esp-nimble head: 95bd8644abf4a410dd3fb914468d3a23ac9bbec2 nimble-1.2.0-idf branch) Logs:

Code: Select all

I (30) boot: ESP-IDF v4.2 2nd stage bootloader
I (30) boot: compile time 22:39:39
I (30) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0c008 ( 49160) map
I (132) esp_image: segment 1: paddr=0x0001c030 vaddr=0x3ffbdb60 size=0x033d8 ( 13272) load
I (137) esp_image: segment 2: paddr=0x0001f410 vaddr=0x40080000 size=0x00404 (  1028) load
0x40080000: _WindowOverflow4 at /home/hrishi/open_source/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (139) esp_image: segment 3: paddr=0x0001f81c vaddr=0x40080404 size=0x007fc (  2044) load
I (148) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x4fbcc (326604) map
0x400d0020: _stext at ??:?

I (280) esp_image: segment 5: paddr=0x0006fbf4 vaddr=0x40080c00 size=0x146ec ( 83692) load
I (329) boot: Loaded app from partition at offset 0x10000
I (329) boot: Disabling RNG early entropy source...
I (329) cpu_start: Pro cpu up.
I (333) cpu_start: Application information:
I (338) cpu_start: Project name:     bleprph
I (343) cpu_start: App version:      v4.2
I (347) cpu_start: Compile time:     Feb 22 2021 22:39:34
I (354) cpu_start: ELF file SHA256:  8d86bd2e142c604f...
I (360) cpu_start: ESP-IDF:          v4.2
I (364) cpu_start: Starting app cpu, entry point is 0x40081890
0x40081890: call_start_cpu1 at /home/hrishi/open_source/esp-idf/components/esp32/cpu_start.c:287

I (0) cpu_start: App cpu up.
I (375) heap_init: Initializing. RAM available for dynamic allocation:
I (382) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (388) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (394) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (400) heap_init: At 3FFC3800 len 0001C800 (114 KiB): DRAM
I (406) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (412) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (419) heap_init: At 400952EC len 0000AD14 (43 KiB): IRAM
I (425) cpu_start: Pro cpu start user code
I (444) spi_flash: detected chip: gd
I (444) spi_flash: flash io: dio
W (444) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (454) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
W (540) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:246328
I (540) BTDM_INIT: BT controller compile version [3723d5b]
I (540) system_api: Base MAC address is not set
I (540) system_api: read default base MAC address from EFUSE
I (640) phy: phy_version: 4500, 0cd6843, Sep 17 2020, 15:37:07, 0, 0
W (870) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (4870) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232264
GAP procedure initiated: stop advertising.
W (4870) NimBLE_BLE_PRPH: DeINIT BLE OK
W (9870) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (9870) BTDM_INIT: BT controller compile version [3723d5b]
W (10120) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (15120) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (15120) NimBLE_BLE_PRPH: DeINIT BLE OK
W (20120) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (20120) BTDM_INIT: BT controller compile version [3723d5b]
W (20350) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (25350) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (25350) NimBLE_BLE_PRPH: DeINIT BLE OK
W (30350) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (30350) BTDM_INIT: BT controller compile version [3723d5b]
W (30590) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (35590) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (35590) NimBLE_BLE_PRPH: DeINIT BLE OK
W (40590) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (40590) BTDM_INIT: BT controller compile version [3723d5b]
W (40830) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
W (45840) NimBLE_BLE_PRPH: DEINIT NIMBLE;HEAP:232260 <<<<<<<<<<<<<<<<
GAP procedure initiated: stop advertising.
W (45840) NimBLE_BLE_PRPH: DeINIT BLE OK
W (50840) NimBLE_BLE_PRPH: INIT NIMBLE;HEAP:262372
I (50840) BTDM_INIT: BT controller compile version [3723d5b]
W (51090) NimBLE_BLE_PRPH: BLE Host Task Started
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0

Can you please check once?
Hello @ESP_Hrishi,

What should I need to add/edit in "esp-nimble head: 95bd8644abf4a410dd3fb914468d3a23ac9bbec2 nimble-1.2.0-idf branch" to let it work?

Or are you saying that my test example with "ESP-IDF Github head: c40f2590bf759ff60ef122afa79b4ec04e7633d2 esp-nimble head: 95bd8644abf4a410dd3fb914468d3a23ac9bbec2 nimble-1.2.0-idf branch" is working as expected (no leak)?

In your first reply you confirmed there was an issue, so at this point I do not understand if my test was wrong or I need to edit/patch some code of "esp-nimble"

Thanks!

Who is online

Users browsing this forum: No registered users and 46 guests