nimble/iso: Fix potential memory leak
This fixes potential BIG memory leak in case ble_hs_hci_cmd_tx returned
an error.
If the error is returned, the code will free the allocated BIG and
BISes.
diff --git a/nimble/host/src/ble_iso.c b/nimble/host/src/ble_iso.c
index 76bc948..004b1fc 100644
--- a/nimble/host/src/ble_iso.c
+++ b/nimble/host/src/ble_iso.c
@@ -233,6 +233,7 @@
{
struct ble_hci_le_create_big_cp cp = { 0 };
struct ble_iso_big *big;
+ int rc;
cp.adv_handle = create_params->adv_handle;
if (create_params->bis_cnt > MYNEWT_VAL(BLE_ISO_MAX_BISES)) {
@@ -272,11 +273,16 @@
memcpy(cp.broadcast_code, big_params->broadcast_code, 16);
}
- *big_handle = big->handle;
+ rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CREATE_BIG),
+ &cp, sizeof(cp),NULL, 0);
+ if (rc != 0) {
+ ble_iso_big_free(big);
+ } else {
+ *big_handle = big->handle;
+ }
- return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_CREATE_BIG),
- &cp, sizeof(cp),NULL, 0);
+ return rc;
}
int