linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] gatt: Fix memory leak in profile_add
Date: Fri, 22 May 2015 15:23:04 +0300	[thread overview]
Message-ID: <20150522122304.GA5680@t440s.lan> (raw)
In-Reply-To: <1432021797-24630-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Tue, May 19, 2015, Andrei Emeltchenko wrote:
> Cleanup memory correctly.
> ---
>  src/gatt-database.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gatt-database.c b/src/gatt-database.c
> index dd80aa0..ca514db 100644
> --- a/src/gatt-database.c
> +++ b/src/gatt-database.c
> @@ -2299,8 +2299,11 @@ static int profile_add(struct external_profile *profile, const char *uuid)
>  		return -ENOMEM;
>  
>  	p->remote_uuid = (const void *) g_strdup(uuid);
> -	if (!p->remote_uuid)
> +	if (!p->remote_uuid) {
> +		g_free((void *) p->name);
> +		free((void *) p);
>  		return -ENOMEM;
> +	}
>  
>  	p->auto_connect = true;

Applied, but we need to do something about the 'const char *' members of
btd_profile. If we're using them to store non-const values they
shouldn't be declared const to begin with. If someone wants to
contribute this change the btd_profile the definition should also have a
comment that the management of these values is left to the higher-level
implementation (i.e. nothing needed for the stack based ones, and
g_free/free needed for ext_profile and the GATT stuff).

Johan

      reply	other threads:[~2015-05-22 12:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-19  7:49 [PATCH] gatt: Fix memory leak in profile_add Andrei Emeltchenko
2015-05-22 12:23 ` Johan Hedberg [this message]

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=20150522122304.GA5680@t440s.lan \
    --to=johan.hedberg@gmail.com \
    --cc=Andrei.Emeltchenko.news@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).