dnsproxy: Check GIO channel for NULL before use
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 16 Nov 2012 12:12:46 +0000 (14:12 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 19 Nov 2012 12:53:24 +0000 (14:53 +0200)
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

index bfd0e3e..01bcc51 100644 (file)
@@ -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);