linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix memory leak in adapter_service_ins_rem()
@ 2010-12-19  1:56 Anderson Lizardo
  2010-12-19  8:48 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Anderson Lizardo @ 2010-12-19  1:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

---
 src/adapter.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5118306..407522f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -980,7 +980,7 @@ static void adapter_service_ins_rem(const bdaddr_t *bdaddr, void *rec,
 							gboolean insert)
 {
 	struct btd_adapter *adapter;
-	GSList *adapters;
+	GSList *l, *adapters;
 
 	adapters = NULL;
 
@@ -995,8 +995,8 @@ static void adapter_service_ins_rem(const bdaddr_t *bdaddr, void *rec,
 		/* Emit D-Bus msg to all adapters */
 		adapters = manager_get_adapters();
 
-	for (; adapters; adapters = adapters->next) {
-		adapter = adapters->data;
+	for (l = adapters; l; l = l->next) {
+		adapter = l->data;
 
 		if (insert == TRUE)
 			adapter->services = sdp_list_insert_sorted(
@@ -1008,6 +1008,9 @@ static void adapter_service_ins_rem(const bdaddr_t *bdaddr, void *rec,
 
 		adapter_emit_uuids_updated(adapter);
 	}
+
+	if (bacmp(bdaddr, BDADDR_ANY) != 0)
+		g_slist_free(adapters);
 }
 
 void adapter_service_insert(const bdaddr_t *bdaddr, void *rec)
-- 
1.7.0.4


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

* Re: [PATCH] Fix memory leak in adapter_service_ins_rem()
  2010-12-19  1:56 [PATCH] Fix memory leak in adapter_service_ins_rem() Anderson Lizardo
@ 2010-12-19  8:48 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2010-12-19  8:48 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-bluetooth

Hi Lizardo,

On Sat, Dec 18, 2010, Anderson Lizardo wrote:
> ---
>  src/adapter.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)

Thanks for catching this, however I went ahead and pushed a slightly
different (and imho simpler) fix. manager_find_adapter needs to iterate
through adapters while comparing addresses anyway so we might as well do
the address comparison within the for-loop in adapter_service_ins_rem().
That way there's no need to create an artificial list for the specific
adapter case.

Johan

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

end of thread, other threads:[~2010-12-19  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-19  1:56 [PATCH] Fix memory leak in adapter_service_ins_rem() Anderson Lizardo
2010-12-19  8:48 ` 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).