mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-29 18:27:20 +02:00
Merge branch 'bugfix/blufi_deinit_memory_leak_v5.3' into 'release/v5.3'
fix(nimble): Fix memory leak issue in Blufi example (v5.3) See merge request espressif/esp-idf!35313
This commit is contained in:
@ -44,6 +44,7 @@ void esp_blufi_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *a
|
||||
|
||||
/* Initialise gatt server */
|
||||
int esp_blufi_gatt_svr_init(void);
|
||||
int esp_blufi_gatt_svr_deinit(void);
|
||||
void esp_blufi_btc_init(void);
|
||||
void esp_blufi_btc_deinit(void);
|
||||
#endif
|
||||
|
@ -240,6 +240,32 @@ static void init_gatt_values(void)
|
||||
|
||||
}
|
||||
|
||||
static void deinit_gatt_values(void)
|
||||
{
|
||||
int i = 0;
|
||||
const struct ble_gatt_svc_def *svc;
|
||||
const struct ble_gatt_chr_def *chr;
|
||||
const struct ble_gatt_dsc_def *dsc;
|
||||
|
||||
for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) {
|
||||
for (chr = svc->characteristics; chr && chr->uuid; chr++) {
|
||||
if (i < SERVER_MAX_VALUES && gatt_values[i].buf != NULL) {
|
||||
os_mbuf_free(gatt_values[i].buf); /* Free the buffer */
|
||||
gatt_values[i].buf = NULL; /* Nullify the pointer to avoid dangling references */
|
||||
}
|
||||
++i;
|
||||
|
||||
for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) {
|
||||
if (i < SERVER_MAX_VALUES && gatt_values[i].buf != NULL) {
|
||||
os_mbuf_free(gatt_values[i].buf); /* Free the buffer */
|
||||
gatt_values[i].buf = NULL; /* Nullify the pointer to avoid dangling references */
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int esp_blufi_gatt_svr_init(void)
|
||||
{
|
||||
int rc;
|
||||
@ -260,6 +286,18 @@ int esp_blufi_gatt_svr_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int esp_blufi_gatt_svr_deinit(void)
|
||||
{
|
||||
deinit_gatt_values();
|
||||
|
||||
ble_gatts_free_svcs();
|
||||
/* Deinitialize BLE GATT and GAP services */
|
||||
ble_svc_gatt_deinit();
|
||||
ble_svc_gap_deinit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
esp_blufi_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
|
Submodule components/bt/host/nimble/nimble updated: 2b25c70cae...41df5f2e69
@ -233,14 +233,17 @@ esp_err_t esp_blufi_host_deinit(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
esp_blufi_gatt_svr_deinit();
|
||||
ret = nimble_port_stop();
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (ret == 0) {
|
||||
esp_nimble_deinit();
|
||||
}
|
||||
|
||||
ret = esp_blufi_profile_deinit();
|
||||
if(ret != ESP_OK) {
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user