Linux bluetooth development
 help / color / mirror / Atom feed
From: Paulo Borges <paulo.borges@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Paulo Borges <paulo.borges@openbossa.org>
Subject: [PATCH 3/4] gatt: Fix memory leak in characteristic discovery
Date: Fri, 30 Nov 2012 15:31:32 -0300	[thread overview]
Message-ID: <1354300294-9105-3-git-send-email-paulo.borges@openbossa.org> (raw)
In-Reply-To: <1354300294-9105-1-git-send-email-paulo.borges@openbossa.org>

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 963fa20..b834b13 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]);
-- 
1.7.9.5


  parent reply	other threads:[~2012-11-30 18:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-30 18:31 [PATCH 1/4] gas: Fix memory leak at gas struct removal Paulo Borges
2012-11-30 18:31 ` [PATCH 2/4] input: Fix memory leak at hogdev " Paulo Borges
2012-11-30 18:31 ` Paulo Borges [this message]
2012-11-30 18:31 ` [PATCH 4/4] gatt: Improve characteristics discovery Paulo Borges
2012-12-01  9:11 ` [PATCH 1/4] gas: Fix memory leak at gas struct removal Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354300294-9105-3-git-send-email-paulo.borges@openbossa.org \
    --to=paulo.borges@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox