- fix coverity
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_peer.c
index 51af0452777ac09eac2128a44529aec0595dd323..fa16db4bbb6b6e99c97b1be34607f385538d84a3 100644 (file)
@@ -387,7 +387,6 @@ notify_broken (void *cls,
  * Remove the direct path to the peer.
  *
  * @param peer Peer to remove the direct path from.
- *
  */
 static struct CadetPeerPath *
 pop_direct_path (struct CadetPeer *peer)
@@ -398,7 +397,9 @@ pop_direct_path (struct CadetPeer *peer)
   {
     if (2 >= iter->length)
     {
-      GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+      GNUNET_CONTAINER_DLL_remove (peer->path_head,
+                                  peer->path_tail,
+                                  iter);
       return iter;
     }
   }
@@ -454,8 +455,6 @@ core_connect (void *cls,
 
   GNUNET_assert (NULL == neighbor->connections);
   neighbor->connections = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
-  GNUNET_assert (NULL != neighbor->connections);
-
   GNUNET_STATISTICS_update (stats,
                             "# peers",
                             1,
@@ -500,11 +499,14 @@ core_disconnect (void *cls,
          "DISCONNECTED %s <= %s\n",
          own_id, GNUNET_i2s (peer));
   direct_path = pop_direct_path (p);
-  GNUNET_CONTAINER_multihashmap_iterate (p->connections,
-                                         &notify_broken,
-                                         p);
-  GNUNET_CONTAINER_multihashmap_destroy (p->connections);
-  p->connections = NULL;
+  if (NULL != p->connections)
+  {
+    GNUNET_CONTAINER_multihashmap_iterate (p->connections,
+                                           &notify_broken,
+                                           p);
+    GNUNET_CONTAINER_multihashmap_destroy (p->connections);
+    p->connections = NULL;
+  }
   if (NULL != p->core_transmit)
   {
     GNUNET_CORE_notify_transmit_ready_cancel (p->core_transmit);
@@ -750,7 +752,8 @@ peer_destroy (struct CadetPeer *peer)
        "destroying peer %s\n",
        GNUNET_i2s (&id));
 
-  if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
+  if (GNUNET_YES !=
+      GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
   {
     GNUNET_break (0);
     LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n");
@@ -772,9 +775,8 @@ peer_destroy (struct CadetPeer *peer)
   {
     GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (peer->connections));
     GNUNET_CONTAINER_multihashmap_destroy (peer->connections);
+    peer->connections = NULL;
   }
-  if (NULL != peer->core_transmit)
-    GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit);
   if (NULL != peer->hello_offer)
   {
     GNUNET_TRANSPORT_offer_hello_cancel (peer->hello_offer);
@@ -789,6 +791,13 @@ peer_destroy (struct CadetPeer *peer)
   {
     GCP_queue_destroy (peer->queue_head, GNUNET_YES, GNUNET_NO, 0);
   }
+  if (NULL != peer->core_transmit)
+  {
+    GNUNET_break (0); /* GCP_queue_destroy should've cancelled it! */
+    GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit);
+    peer->core_transmit = NULL;
+  }
+
   GNUNET_free_non_null (peer->hello);
   GNUNET_free (peer);
   return GNUNET_OK;
@@ -811,6 +820,7 @@ shutdown_peer (void *cls,
 {
   struct CadetPeer *p = value;
   struct CadetTunnel *t = p->tunnel;
+
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  shutting down %s\n", GCP_2s (p));
   if (NULL != t)
     GCT_destroy (t);
@@ -846,12 +856,8 @@ static void
 delayed_search (void *cls)
 {
   struct CadetPeer *peer = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   peer->search_delayed = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
   GCC_check_connections ();
   GCP_start_search (peer);
   GCC_check_connections ();
@@ -1934,8 +1940,9 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create)
 
 
 /**
- * Retrieve the CadetPeer stucture associated with the peer. Optionally create
- * one and insert it in the appropriate structures if the peer is not known yet.
+ * Retrieve the CadetPeer stucture associated with the
+ * peer. Optionally create one and insert it in the appropriate
+ * structures if the peer is not known yet.
  *
  * @param peer Short identity of the peer.
  * @param create #GNUNET_YES if a new peer should be created if unknown.
@@ -2223,7 +2230,8 @@ GCP_add_path (struct CadetPeer *peer,
       }
     }
   }
-  GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
+  GNUNET_CONTAINER_DLL_insert_tail (peer->path_head,
+                                   peer->path_tail,
                                     path);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  added last\n");
 
@@ -2300,7 +2308,8 @@ GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed)
  * @param path Path to remove. Is always destroyed .
  */
 void
-GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
+GCP_remove_path (struct CadetPeer *peer,
+                struct CadetPeerPath *path)
 {
   struct CadetPeerPath *iter;
   struct CadetPeerPath *next;
@@ -2309,7 +2318,8 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
   GNUNET_assert (myid == path->peers[0]);
   GNUNET_assert (peer->id == path->peers[path->length - 1]);
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Removing path %p (%u) from %s\n",
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Removing path %p (%u) from %s\n",
        path, path->length, GCP_2s (peer));
 
   for (iter = peer->path_head; NULL != iter; iter = next)
@@ -2317,7 +2327,9 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
     next = iter->next;
     if (0 == path_cmp (path, iter))
     {
-      GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+      GNUNET_CONTAINER_DLL_remove (peer->path_head,
+                                  peer->path_tail,
+                                  iter);
       if (iter != path)
         path_destroy (iter);
     }
@@ -2512,7 +2524,8 @@ GCP_get_tunnel (const struct CadetPeer *peer)
  * @param hello Hello message.
  */
 void
-GCP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello)
+GCP_set_hello (struct CadetPeer *peer,
+              const struct GNUNET_HELLO_Message *hello)
 {
   struct GNUNET_HELLO_Message *old;
   size_t size;