Make failure branches deallocate memory before leaving. --- profiles/audio/bap.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index ee7c8bc49..11e7b1546 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -2954,31 +2954,32 @@ static int bap_bcast_probe(struct btd_service *service) struct btd_adapter *adapter = device_get_adapter(device); struct btd_gatt_database *database = btd_adapter_get_database(adapter); struct bap_data *data; + struct bt_bap *bap; if (!btd_adapter_has_exp_feature(adapter, EXP_FEAT_ISO_SOCKET)) { error("BAP requires ISO Socket which is not enabled"); return -ENOTSUP; } - data = bap_data_new(device); - data->service = service; - data->adapter = adapter; - data->device = device; - data->bap = bt_bap_new(btd_gatt_database_get_db(database), + bap = bt_bap_new(btd_gatt_database_get_db(database), btd_gatt_database_get_db(database)); - if (!data->bap) { + if (!bap) { error("Unable to create BAP instance"); - free(data); return -EINVAL; } - data->bcast_snks = queue_new(); + bt_bap_set_user_data(bap, service); - bt_bap_set_user_data(data->bap, service); - - if (!bt_bap_attach(data->bap, NULL)) { + if (!bt_bap_attach(bap, NULL)) { error("BAP unable to attach"); + bt_bap_unref(bap); return -EINVAL; } + data = bap_data_new(device); + data->service = service; + data->adapter = adapter; + data->device = device; + data->bap = bap; + data->bcast_snks = queue_new(); bap_data_add(data); -- 2.34.1