Fixed (double) asyncns cancellation bug, and made the code more robust.
authorSenko Rasic <senko.rasic@collabora.co.uk>
Thu, 13 Sep 2007 18:03:28 +0200
changeset 276 3b05eae99e1a
parent 275 37937c612f62
child 277 f3ad3d16c8b5
Fixed (double) asyncns cancellation bug, and made the code more robust.
loudmouth/lm-socket.c
--- a/loudmouth/lm-socket.c	Thu Sep 06 16:37:16 2007 +0200
+++ b/loudmouth/lm-socket.c	Thu Sep 13 18:03:28 2007 +0200
@@ -760,18 +760,11 @@
 {
 	if (socket == NULL)
 		return;
+
 	if (socket->asyncns_ctx) {
-		if (socket->watch_resolv) {
-			g_source_destroy (socket->watch_resolv);
-			socket->watch_resolv = NULL;
-		}
-		if (socket->resolv_channel) {
-			g_io_channel_close (socket->resolv_channel);
-			socket->resolv_channel = NULL;
-		}
+		assert (socket->resolv_query != NULL);
 		asyncns_cancel (socket->asyncns_ctx, socket->resolv_query);
-		asyncns_free (socket->asyncns_ctx);
-		socket->asyncns_ctx = NULL;
+		_asyncns_done (socket);
 	}
 }
 
@@ -807,15 +800,22 @@
 static void
 _asyncns_done (LmSocket *socket)
 {
-	if (socket->resolv_channel == NULL)
-		return;
+	if (socket->resolv_channel != NULL) {
+		g_io_channel_unref (socket->resolv_channel);
+		socket->resolv_channel = NULL;
+	}
+ 
+	if (socket->watch_resolv) {
+		g_source_destroy(socket->watch_resolv);
+		socket->watch_resolv = NULL;
+	}
 
-	g_io_channel_unref (socket->resolv_channel);
-	socket->resolv_channel = NULL;
-	asyncns_free (socket->asyncns_ctx);
-	socket->asyncns_ctx = NULL;
-	socket->watch_resolv = NULL;
-	socket->resolv_query = NULL;
+	if (socket->asyncns_ctx) {
+		asyncns_free (socket->asyncns_ctx);
+		socket->asyncns_ctx = NULL;
+	}
+
+ 	socket->resolv_query = NULL;
 }
 
 static gboolean