Skip to contentSkip to conversation

shared/gatt-client: Fix possible crash

PATCH Applied Luiz Augusto von Dentz 1 participant 2 messages Apr 1, 2015 – Apr 2, 2015 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/gatt-client: Fix possible crash

From: Luiz Augusto von Dentz <[email protected]>

Similar to issue found with unit test it is necessary to protect bt_gatt_client instance before calling the callback otherwise it may destroy it causing a crash.

---
 src/shared/gatt-client.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-client.c +4 -1
index df994d7..b92d7b1 100644
@@ -2456,14 +2456,17 @@ static void complete_write_long_op(struct request *req, bool success,
 	if (req->att_id)
 		return;
 
-
 	request_unref(req);
 	success = false;
 
+	bt_gatt_client_ref(op->client);
+
 	if (op->callback)
 		op->callback(success, reliable_error, att_ecode, op->user_data);
 
 	start_next_long_write(op->client);
+
+	bt_gatt_client_unref(op->client);
 }
 
 static void prepare_write_cb(uint8_t opcode, const void *pdu, uint16_t length,
Signature · 1 line
2.1.0
author maintainer Applied
#1 lore raw

Hi,

Quoted 33 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Similar to issue found with unit test it is necessary to protect bt_gatt_client instance before calling the callback otherwise it may destroy it causing a crash.

---
 src/shared/gatt-client.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-client.c +4 -2
index df994d7..b92d7b1 100644
@@ -2456,14 +2456,17 @@ static void complete_write_long_op(struct request *req, bool success,
        if (req->att_id)
                return;
 
-
        request_unref(req);
        success = false;
 
+       bt_gatt_client_ref(op->client);
+
        if (op->callback)
                op->callback(success, reliable_error, att_ecode, op->user_data);
 
        start_next_long_write(op->client);
+
+       bt_gatt_client_unref(op->client);
 }
 
 static void prepare_write_cb(uint8_t opcode, const void *pdu, uint16_t length,
--
Quoted 1 line

2.1.0

Applied.

Signature · 1 line
Luiz Augusto von Dentz