fix(nimble): fix memory leak issue in Blufi example

This commit is contained in:
Astha Verma
2024-11-19 17:05:41 +05:30
committed by Rahul Tank
parent 82401dd24d
commit c885e1bd32
6 changed files with 28 additions and 2 deletions
+1 -1
View File
@@ -1095,7 +1095,7 @@ STAILQ_HEAD(ble_gatts_clt_cfg_list, ble_gatts_clt_cfg);
* BLE_HS_ENOMEM on heap exhaustion.
*/
int ble_gatts_add_svcs(const struct ble_gatt_svc_def *svcs);
void ble_gatts_free_svcs(void);
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
/**
* Adds a set of services for registration. All services added
@@ -58,6 +58,7 @@ int ble_svc_gap_device_key_material_set(uint8_t *session_key, uint8_t *iv);
#endif
void ble_svc_gap_init(void);
void ble_svc_gap_deinit(void);
#ifdef __cplusplus
}
@@ -370,3 +370,9 @@ ble_svc_gap_init(void)
SYSINIT_PANIC_ASSERT(rc == 0);
#endif
}
void
ble_svc_gap_deinit(void)
{
ble_gatts_free_svcs();
}
@@ -51,7 +51,7 @@ uint8_t ble_svc_gatt_get_csfs();
uint8_t ble_svc_gatt_get_local_cl_supported_feat(void);
void ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle);
void ble_svc_gatt_init(void);
void ble_svc_gatt_deinit(void);
#ifdef __cplusplus
}
#endif
@@ -249,3 +249,9 @@ ble_svc_gatt_init(void)
ble_svc_gatt_local_cl_sup_feat |= (1 << BLE_SVC_GATT_CLI_SUP_FEAT_ROBUST_CATCHING_BIT);
}
}
void
ble_svc_gatt_deinit(void)
{
ble_gatts_free_svcs();
}
+13
View File
@@ -3025,6 +3025,19 @@ done:
return rc;
}
void ble_gatts_free_svcs(void)
{
/* Ensure the memory is freed only if it was previously allocated */
if (ble_gatts_svc_defs != NULL) {
/* Free the memory for the service definitions */
free(ble_gatts_svc_defs);
/* Set the pointer to NULL to avoid dangling pointer */
ble_gatts_svc_defs = NULL;
/* Reset the number of service definitions to 0 */
ble_gatts_num_svc_defs = 0;
}
}
int
ble_gatts_svc_set_visibility(uint16_t handle, int visible)
{