Skip to content

Commit

Permalink
Fixed some memory was not released after bluetooth controller initial…
Browse files Browse the repository at this point in the history
…ization failed on ESP32
  • Loading branch information
Weijian-Espressif committed Dec 19, 2022
1 parent dfa9a81 commit 5fff471
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
46 changes: 20 additions & 26 deletions components/bt/controller/esp32/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ static void *customer_queue_create_hlevel_wrapper(uint32_t queue_len, uint32_t i
#endif /* CONFIG_BTDM_CTRL_HLI */
static void interrupt_l3_disable(void);
static void interrupt_l3_restore(void);
static void bt_controller_deinit_internal(void);

/* Local variable definition
***************************************************************************
Expand Down Expand Up @@ -1576,26 +1577,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
return ESP_OK;

error:
#ifdef CONFIG_PM_ENABLE
if (!s_btdm_allow_light_sleep) {
if (s_light_sleep_pm_lock != NULL) {
esp_pm_lock_delete(s_light_sleep_pm_lock);
s_light_sleep_pm_lock = NULL;
}
}
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
}
if (s_btdm_slp_tmr != NULL) {
esp_timer_delete(s_btdm_slp_tmr);
s_btdm_slp_tmr = NULL;
}
#endif
if (s_wakeup_req_sem) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}

bt_controller_deinit_internal();

return err;
}

Expand All @@ -1607,6 +1591,13 @@ esp_err_t esp_bt_controller_deinit(void)

btdm_controller_deinit();

bt_controller_deinit_internal();

return ESP_OK;
}

static void bt_controller_deinit_internal(void)
{
periph_module_disable(PERIPH_BT_MODULE);

#ifdef CONFIG_PM_ENABLE
Expand All @@ -1628,11 +1619,16 @@ esp_err_t esp_bt_controller_deinit(void)

s_pm_lock_acquired = false;
#endif
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;

free(osi_funcs_p);
osi_funcs_p = NULL;
if (s_wakeup_req_sem) {
semphr_delete_wrapper(s_wakeup_req_sem);
s_wakeup_req_sem = NULL;
}

if (osi_funcs_p) {
free(osi_funcs_p);
osi_funcs_p = NULL;
}

btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;

Expand All @@ -1642,8 +1638,6 @@ esp_err_t esp_bt_controller_deinit(void)
esp_bt_power_domain_off();

esp_phy_modem_deinit();

return ESP_OK;
}

static void bt_controller_shutdown(void* arg)
Expand Down
2 changes: 1 addition & 1 deletion components/bt/controller/lib_esp32

0 comments on commit 5fff471

Please sign in to comment.