public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Fix memory leak in src/rfkill.c
@ 2010-12-20  4:29 Anderson Lizardo
  2010-12-20  4:29 ` [PATCH 2/3] Fix memory leak in src/sdpd-server.c Anderson Lizardo
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Anderson Lizardo @ 2010-12-20  4:29 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

Watches must be removed with g_source_remove() otherwise they leak a
reference count to the GIOChannel and internal memory allocations.

Also g_io_channel_set_close_on_unref() is used, so there is no need to
call g_io_channel_shutdown() by hand.
---
 src/rfkill.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/rfkill.c b/src/rfkill.c
index 75397b8..6e9e040 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -139,6 +139,7 @@ static gboolean rfkill_event(GIOChannel *chan,
 }
 
 static GIOChannel *channel = NULL;
+static guint watch_id = 0;
 
 void rfkill_init(void)
 {
@@ -156,8 +157,8 @@ void rfkill_init(void)
 	channel = g_io_channel_unix_new(fd);
 	g_io_channel_set_close_on_unref(channel, TRUE);
 
-	g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
-							rfkill_event, NULL);
+	watch_id = g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP |
+						G_IO_ERR, rfkill_event, NULL);
 }
 
 void rfkill_exit(void)
@@ -165,7 +166,9 @@ void rfkill_exit(void)
 	if (!channel)
 		return;
 
-	g_io_channel_shutdown(channel, TRUE, NULL);
+	if (watch_id > 0)
+		g_source_remove(watch_id);
+
 	g_io_channel_unref(channel);
 
 	channel = NULL;
-- 
1.7.0.4


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

end of thread, other threads:[~2010-12-20 11:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-20  4:29 [PATCH 1/3] Fix memory leak in src/rfkill.c Anderson Lizardo
2010-12-20  4:29 ` [PATCH 2/3] Fix memory leak in src/sdpd-server.c Anderson Lizardo
2010-12-20  4:29 ` [PATCH 3/3] Fix memory leaks in btio/btio.c Anderson Lizardo
2010-12-20  9:20   ` Luiz Augusto von Dentz
2010-12-20 11:36     ` Anderson Lizardo
2010-12-20 11:57       ` Anderson Lizardo
2010-12-20  8:16 ` [PATCH 1/3] Fix memory leak in src/rfkill.c Johan Hedberg

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