This is an automated email from the ASF dual-hosted git repository. janc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 75b35adb697c263d3e8f85be80ac5a39a45e15bd Author: Mariusz Skamra <[email protected]> AuthorDate: Tue Mar 5 11:57:55 2024 +0100 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. --- nimble/host/src/ble_iso.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nimble/host/src/ble_iso.c b/nimble/host/src/ble_iso.c index 76bc94803..004b1fc47 100644 --- a/nimble/host/src/ble_iso.c +++ b/nimble/host/src/ble_iso.c @@ -233,6 +233,7 @@ ble_iso_create_big(const struct ble_iso_create_big_params *create_params, { 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 @@ ble_iso_create_big(const struct ble_iso_create_big_params *create_params, 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
