From d2555dcbfb883bc8fe1c91459f463b2763baac72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Tue, 9 Apr 2024 11:21:55 +0200 Subject: [PATCH] host/audio/ble_iso.c: fix deallocation of BIS Freeing memory back to BIS pool in loop while changing removing ISO connections from list lead to memory leak. Now, memory is freed in separate loop. --- nimble/host/src/ble_iso.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nimble/host/src/ble_iso.c b/nimble/host/src/ble_iso.c index 004b1fc47..af728d135 100644 --- a/nimble/host/src/ble_iso.c +++ b/nimble/host/src/ble_iso.c @@ -205,6 +205,10 @@ static int ble_iso_big_free(struct ble_iso_big *big) { struct ble_iso_conn *conn; + struct ble_iso_bis *rem_bis[MYNEWT_VAL(BLE_ISO_MAX_BISES)] = { + [0 ... MYNEWT_VAL(BLE_ISO_MAX_BISES) - 1] = NULL + }; + uint8_t i = 0; SLIST_FOREACH(conn, &ble_iso_conns, next) { struct ble_iso_bis *bis; @@ -216,10 +220,14 @@ ble_iso_big_free(struct ble_iso_big *big) bis = CONTAINER_OF(conn, struct ble_iso_bis, conn); if (bis->big == big) { SLIST_REMOVE(&ble_iso_conns, conn, ble_iso_conn, next); - os_memblock_put(&ble_iso_bis_pool, bis); + rem_bis[i++] = bis; } } + while (i > 0) { + os_memblock_put(&ble_iso_bis_pool, rem_bis[--i]); + } + SLIST_REMOVE(&ble_iso_bigs, big, ble_iso_big, next); os_memblock_put(&ble_iso_big_pool, big); return 0;