asserts
[oweals/gnunet.git] / src / util / server_nc.c
index 9b6eefe1fc8a87fd65d9ec4f5baf1312c7d13c06..88de62c63f4a20a1b1cb9112ca1825b1969912f1 100644 (file)
@@ -146,6 +146,11 @@ handle_client_disconnect (void *cls,
   struct ClientList *prev;
   struct PendingMessageList *pml;
 
+  if (client == NULL)
+    {
+      nc->server = NULL;
+      return;
+    }
   prev = NULL;
   pos = nc->clients;
   while (NULL != pos)
@@ -167,6 +172,11 @@ handle_client_disconnect (void *cls,
       GNUNET_free (pml);
     }
   GNUNET_SERVER_client_drop (client);
+  if (pos->th != NULL)
+    {
+      GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
+      pos->th = NULL;
+    }
   GNUNET_free (pos);
 }
 
@@ -210,8 +220,8 @@ GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationCon
   while (NULL != (pos = nc->clients))
     {
       nc->clients = pos->next;
-      GNUNET_SERVER_receive_done (pos->client, GNUNET_NO);
       GNUNET_SERVER_client_drop (pos->client); 
+      GNUNET_SERVER_receive_done (pos->client, GNUNET_NO);
       while (NULL != (pml = pos->pending_head))
        {
          pos->pending_head = pml->next;
@@ -219,9 +229,10 @@ GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationCon
        }
       GNUNET_free (pos);
     }
-  GNUNET_SERVER_disconnect_notify_cancel (nc->server,
-                                         &handle_client_disconnect,
-                                         nc);
+  if (nc->server != NULL)
+    GNUNET_SERVER_disconnect_notify_cancel (nc->server,
+                                           &handle_client_disconnect,
+                                           nc);
   GNUNET_free (nc);
 }