From 1db97762e976bdf9304ffc9873b052fbaec48de1 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 1 Apr 2015 15:16:14 +0300 Subject: [PATCH] shared/gatt-client: Fix possible crash 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(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index df994d70e..b92d7b17b 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -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, -- 2.47.3