Skip to contentSkip to conversation

Bluetooth: Fix memory leak in hci_connect_le_scan

PATCH In review Navid Emamdoost 2 participants 2 messages Nov 21, 2019 – Nov 22, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: Fix memory leak in hci_connect_le_scan

In the implementation of hci_connect_le_scan() when conn is added via hci_conn_add(), if hci_explicit_conn_params_set() fails the allocated memory for conn is leaked. Use hci_conn_del() to release it.

Fixes f75113a26008 ("Bluetooth: add hci_connect_le_scan")
---
 net/bluetooth/hci_conn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_conn.c +3 -1
index ad5b0ac1f9ce..4472ec02c3e2 100644
@@ -1168,8 +1168,10 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
 	if (!conn)
 		return ERR_PTR(-ENOMEM);
 
-	if (hci_explicit_conn_params_set(hdev, dst, dst_type) < 0)
+	if (hci_explicit_conn_params_set(hdev, dst, dst_type) < 0) {
+		hci_conn_del(conn);
 		return ERR_PTR(-EBUSY);
+	}
 
 	conn->state = BT_CONNECT;
 	set_bit(HCI_CONN_SCANNING, &conn->flags);
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hi Navid,

Quoted 9 lines

In the implementation of hci_connect_le_scan() when conn is added via hci_conn_add(), if hci_explicit_conn_params_set() fails the allocated memory for conn is leaked. Use hci_conn_del() to release it.

Fixes f75113a26008 ("Bluetooth: add hci_connect_le_scan")

---
net/bluetooth/hci_conn.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel