Skip to content

Commit

Permalink
Merge branch 'bugfix/heap_corrupt_in_bt_mem_release_on_esp32_v5.1' in…
Browse files Browse the repository at this point in the history
…to 'release/v5.1'

fix(bt): Fix heap corruption in the call of esp_bt_mem_release on ESP32 (v5.1)

See merge request espressif/esp-idf!32803
  • Loading branch information
jack0c committed Aug 15, 2024
2 parents f6d8ff4 + 4b7286d commit 99395b2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions components/bt/controller/esp32/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,14 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode)
.name = "BT Controller Data"
};

/*
* Free data and BSS section for Bluetooth controller ROM code.
* Note that rom mem release must be performed before section _bt_data_start to _bt_data_end is released,
* otherwise `btdm_dram_available_region` will no longer be available when performing rom mem release and
* thus causing heap corruption.
*/
ret = esp_bt_controller_rom_mem_release(mode);

if (mode == ESP_BT_MODE_BTDM) {
/* Start by freeing Bluetooth BSS section */
if (ret == ESP_OK) {
Expand All @@ -1440,11 +1448,6 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode)
}
}

/* free data and BSS section for Bluetooth controller ROM code */
if (ret == ESP_OK) {
ret = esp_bt_controller_rom_mem_release(mode);
}

return ret;
}

Expand Down

0 comments on commit 99395b2

Please sign in to comment.