[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230109012651.3127529-1-shaozhengchao@huawei.com>
Date: Mon, 9 Jan 2023 09:26:51 +0800
From: Zhengchao Shao <shaozhengchao@...wei.com>
To: <linux-bluetooth@...r.kernel.org>, <netdev@...r.kernel.org>,
<marcel@...tmann.org>, <johan.hedberg@...il.com>,
<luiz.dentz@...il.com>, <davem@...emloft.net>,
<edumazet@...gle.com>, <kuba@...nel.org>, <pabeni@...hat.com>
CC: <brian.gix@...el.com>, <weiyongjun1@...wei.com>,
<yuehaibing@...wei.com>, <shaozhengchao@...wei.com>
Subject: [PATCH] Bluetooth: hci_sync: fix memory leak in hci_update_adv_data()
When hci_cmd_sync_queue() failed in hci_update_adv_data(), inst_ptr is
not freed, which will cause memory leak. Add release process to error
path.
Fixes: 651cd3d65b0f ("Bluetooth: convert hci_update_adv_data to hci_sync")
Signed-off-by: Zhengchao Shao <shaozhengchao@...wei.com>
---
net/bluetooth/hci_sync.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 9e2d7e4b850c..1485501bd72f 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6197,10 +6197,15 @@ static int _update_adv_data_sync(struct hci_dev *hdev, void *data)
int hci_update_adv_data(struct hci_dev *hdev, u8 instance)
{
u8 *inst_ptr = kmalloc(1, GFP_KERNEL);
+ int ret;
if (!inst_ptr)
return -ENOMEM;
*inst_ptr = instance;
- return hci_cmd_sync_queue(hdev, _update_adv_data_sync, inst_ptr, NULL);
+ ret = hci_cmd_sync_queue(hdev, _update_adv_data_sync, inst_ptr, NULL);
+ if (ret)
+ kfree(inst_ptr);
+
+ return ret;
}
--
2.34.1
Powered by blists - more mailing lists