Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] android/tester: Fix valgrind memory warnings
@ 2013-12-20  8:56 Andrei Emeltchenko
  2013-12-20  9:00 ` Andrei Emeltchenko
  2013-12-20  9:12 ` Szymon Janc
  0 siblings, 2 replies; 4+ messages in thread
From: Andrei Emeltchenko @ 2013-12-20  8:56 UTC (permalink / raw)
  To: linux-bluetooth

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

Free device structure allocated during open_bluetooth().
---
 android/android-tester.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 7d7ed88..6007797 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -109,6 +109,7 @@ struct test_data {
 	const void *test_data;
 	pid_t bluetoothd_pid;
 
+	hw_device_t *device;
 	const bt_interface_t *if_bluetooth;
 	const btsock_interface_t *if_sock;
 
@@ -838,6 +839,8 @@ static void setup(struct test_data *data)
 		return;
 	}
 
+	data->device = device;
+
 	data->if_bluetooth = ((bluetooth_device_t *)
 					device)->get_bluetooth_interface();
 	if (!data->if_bluetooth) {
@@ -882,6 +885,9 @@ static void teardown(const void *test_data)
 		data->if_bluetooth = NULL;
 	}
 
+	if (data->device)
+		free(data->device);
+
 	if (data->bluetoothd_pid)
 		waitpid(data->bluetoothd_pid, NULL, 0);
 
-- 
1.8.3.2


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

* [PATCH] android/tester: Fix valgrind memory warnings
  2013-12-20  8:56 [PATCH] android/tester: Fix valgrind memory warnings Andrei Emeltchenko
@ 2013-12-20  9:00 ` Andrei Emeltchenko
  2013-12-20  9:12 ` Szymon Janc
  1 sibling, 0 replies; 4+ messages in thread
From: Andrei Emeltchenko @ 2013-12-20  9:00 UTC (permalink / raw)
  To: linux-bluetooth

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

Free device structure allocated during open_bluetooth().

==26231== 80 bytes in 1 blocks are definitely lost in loss record 25 of
31
==26231==    at 0x4C2A2DB: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26231==    by 0x40F153: open_bluetooth (hal-bluetooth.c:800)
==26231==    by 0x40C8D8: setup (android-tester.c:835)
==26231==    by 0x40CB20: setup_socket_interface_enabled
(android-tester.c:1166)
==26231==    by 0x409C15: setup_callback (tester.c:373)
==26231==    by 0x4E7C3B5: g_main_context_dispatch (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
==26231==    by 0x4E7C707: ??? (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
==26231==    by 0x4E7CB09: g_main_loop_run (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
==26231==    by 0x40A83C: tester_run (tester.c:784)
==26231==    by 0x40362A: main (android-tester.c:1643)
---
 android/android-tester.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 7d7ed88..6007797 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -109,6 +109,7 @@ struct test_data {
 	const void *test_data;
 	pid_t bluetoothd_pid;
 
+	hw_device_t *device;
 	const bt_interface_t *if_bluetooth;
 	const btsock_interface_t *if_sock;
 
@@ -838,6 +839,8 @@ static void setup(struct test_data *data)
 		return;
 	}
 
+	data->device = device;
+
 	data->if_bluetooth = ((bluetooth_device_t *)
 					device)->get_bluetooth_interface();
 	if (!data->if_bluetooth) {
@@ -882,6 +885,9 @@ static void teardown(const void *test_data)
 		data->if_bluetooth = NULL;
 	}
 
+	if (data->device)
+		free(data->device);
+
 	if (data->bluetoothd_pid)
 		waitpid(data->bluetoothd_pid, NULL, 0);
 
-- 
1.8.3.2


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

* Re: [PATCH] android/tester: Fix valgrind memory warnings
  2013-12-20  8:56 [PATCH] android/tester: Fix valgrind memory warnings Andrei Emeltchenko
  2013-12-20  9:00 ` Andrei Emeltchenko
@ 2013-12-20  9:12 ` Szymon Janc
  2013-12-20  9:30   ` Johan Hedberg
  1 sibling, 1 reply; 4+ messages in thread
From: Szymon Janc @ 2013-12-20  9:12 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Free device structure allocated during open_bluetooth().
> ---
>  android/android-tester.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/android/android-tester.c b/android/android-tester.c
> index 7d7ed88..6007797 100644
> --- a/android/android-tester.c
> +++ b/android/android-tester.c
> @@ -109,6 +109,7 @@ struct test_data {
>  	const void *test_data;
>  	pid_t bluetoothd_pid;
>  
> +	hw_device_t *device;
>  	const bt_interface_t *if_bluetooth;
>  	const btsock_interface_t *if_sock;
>  
> @@ -838,6 +839,8 @@ static void setup(struct test_data *data)
>  		return;
>  	}
>  
> +	data->device = device;
> +
>  	data->if_bluetooth = ((bluetooth_device_t *)
>  					device)->get_bluetooth_interface();
>  	if (!data->if_bluetooth) {
> @@ -882,6 +885,9 @@ static void teardown(const void *test_data)
>  		data->if_bluetooth = NULL;
>  	}
>  
> +	if (data->device)
> +		free(data->device);

There is no need to check pointer before passing it to free().

> +
>  	if (data->bluetoothd_pid)
>  		waitpid(data->bluetoothd_pid, NULL, 0);
>  
> 

-- 
BR
Szymon Janc



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

* Re: [PATCH] android/tester: Fix valgrind memory warnings
  2013-12-20  9:12 ` Szymon Janc
@ 2013-12-20  9:30   ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2013-12-20  9:30 UTC (permalink / raw)
  To: Szymon Janc; +Cc: Andrei Emeltchenko, linux-bluetooth

Hi Szymon,

On Fri, Dec 20, 2013, Szymon Janc wrote:
> > Free device structure allocated during open_bluetooth().
> > ---
> >  android/android-tester.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/android/android-tester.c b/android/android-tester.c
> > index 7d7ed88..6007797 100644
> > --- a/android/android-tester.c
> > +++ b/android/android-tester.c
> > @@ -109,6 +109,7 @@ struct test_data {
> >  	const void *test_data;
> >  	pid_t bluetoothd_pid;
> >  
> > +	hw_device_t *device;
> >  	const bt_interface_t *if_bluetooth;
> >  	const btsock_interface_t *if_sock;
> >  
> > @@ -838,6 +839,8 @@ static void setup(struct test_data *data)
> >  		return;
> >  	}
> >  
> > +	data->device = device;
> > +
> >  	data->if_bluetooth = ((bluetooth_device_t *)
> >  					device)->get_bluetooth_interface();
> >  	if (!data->if_bluetooth) {
> > @@ -882,6 +885,9 @@ static void teardown(const void *test_data)
> >  		data->if_bluetooth = NULL;
> >  	}
> >  
> > +	if (data->device)
> > +		free(data->device);
> 
> There is no need to check pointer before passing it to free().

The bigger issue here is that the ->open() caller shouldn't know how the
memory was allocated (or if it was allocated at all for that matter - it
might just be a static variable).

This is really a failure of the API since it doesn't provide a ->close()
callback that could do the right thing.

Johan

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

end of thread, other threads:[~2013-12-20  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20  8:56 [PATCH] android/tester: Fix valgrind memory warnings Andrei Emeltchenko
2013-12-20  9:00 ` Andrei Emeltchenko
2013-12-20  9:12 ` Szymon Janc
2013-12-20  9:30   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox