[PATCH 1/3] dnsproxy: Check GIO channel for NULL before use

patrik.flykt at linux.intel.com patrik.flykt at linux.intel.com
Mon Nov 19 00:48:03 PST 2012


From: Patrik Flykt <patrik.flykt at linux.intel.com>

Check GIO channel for NULL before using it. Also shut down the GIO channel
so that already pending input will not use the free'd structure.
---
 src/dnsproxy.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index bfd0e3e..01bcc51 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -1765,8 +1765,11 @@ static void server_destroy_socket(struct server_data *data)
 		data->timeout = 0;
 	}
 
-	g_io_channel_unref(data->channel);
-	data->channel = NULL;
+	if (data->channel != NULL) {
+		g_io_channel_shutdown(data->channel, TRUE, NULL);
+		g_io_channel_unref(data->channel);
+		data->channel = NULL;
+	}
 
 	g_free(data->incoming_reply);
 	data->incoming_reply = NULL;
@@ -1777,7 +1780,8 @@ static void destroy_server(struct server_data *server)
 	GList *list;
 
 	DBG("interface %s server %s sock %d", server->interface, server->server,
-		g_io_channel_unix_get_fd(server->channel));
+			server->channel != NULL ?
+			g_io_channel_unix_get_fd(server->channel): -1);
 
 	server_list = g_slist_remove(server_list, server);
 	server_destroy_socket(server);
-- 
1.7.10.4




More information about the connman mailing list