From d07b73511740d59e0fba68cc87ad9bc61ca283ad Mon Sep 17 00:00:00 2001 From: Paulo Borges Date: Fri, 30 Nov 2012 15:31:32 -0300 Subject: [PATCH] gatt: Fix memory leak in characteristic discovery If the Discover Characteristics by UUID sub-procedure has been executed and the first characteristic is not the target, a memory leak occurs. This commit fixes this leak by postponing the allocation to after the UUID verification. --- attrib/gatt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/attrib/gatt.c b/attrib/gatt.c index 963fa2038..b834b1345 100644 --- a/attrib/gatt.c +++ b/attrib/gatt.c @@ -475,15 +475,15 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen, } else uuid = att_get_uuid128(&value[5]); + if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid)) + break; + chars = g_try_new0(struct gatt_char, 1); if (!chars) { err = ATT_ECODE_INSUFF_RESOURCES; goto done; } - if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid)) - break; - chars->handle = last; chars->properties = value[2]; chars->value_handle = att_get_u16(&value[3]); -- 2.47.3