linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gatt: Fix memory leak in profile_add
@ 2015-05-19  7:49 Andrei Emeltchenko
  2015-05-22 12:23 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Andrei Emeltchenko @ 2015-05-19  7:49 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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;
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gatt: Fix memory leak in profile_add
  2015-05-19  7:49 [PATCH] gatt: Fix memory leak in profile_add Andrei Emeltchenko
@ 2015-05-22 12:23 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2015-05-22 12:23 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-22 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-19  7:49 [PATCH] gatt: Fix memory leak in profile_add Andrei Emeltchenko
2015-05-22 12:23 ` Johan Hedberg

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).