-log
[oweals/gnunet.git] / src / mesh / mesh_tunnel_tree.c
index 586654a2d2144057a7eab0f432ab2fcfbd3f8f2c..48d052ef726c8ad60ea7bc95441bb2836e26a34d 100644 (file)
@@ -119,7 +119,7 @@ path_new (unsigned int length)
 {
   struct MeshPeerPath *p;
 
-  p = GNUNET_malloc (sizeof (struct MeshPeerPath));
+  p = GNUNET_new (struct MeshPeerPath);
   if (length > 0)
   {
     p->length = length;
@@ -233,7 +233,7 @@ tree_node_new (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer)
 {
   struct MeshTunnelTreeNode *node;
 
-  node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode));
+  node = GNUNET_new (struct MeshTunnelTreeNode);
   node->peer = peer;
   GNUNET_PEER_change_rc (peer, 1);
   node->parent = parent;
@@ -322,7 +322,7 @@ tree_node_update_first_hops (struct MeshTunnelTree *tree,
   GNUNET_PEER_resolve (parent->peer, &id);
   copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
   if (NULL == copy)
-    copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+    copy = GNUNET_new (struct GNUNET_PeerIdentity);
   *copy = *hop;
 
   (void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey,
@@ -417,7 +417,7 @@ tree_new (GNUNET_PEER_Id peer)
 {
   struct MeshTunnelTree *tree;
 
-  tree = GNUNET_malloc (sizeof (struct MeshTunnelTree));
+  tree = GNUNET_new (struct MeshTunnelTree);
   tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
   tree->root = tree_node_new (NULL, peer);
   tree->root->status = MESH_PEER_ROOT;
@@ -496,7 +496,7 @@ tree_get_predecessor (struct MeshTunnelTree *tree)
  *
  * @return peerinfo of the peer who is the first hop in the tunnel
  *         NULL on error
- * 
+ *
  * FIXME use PEER_Id
  */
 struct GNUNET_PeerIdentity *
@@ -647,7 +647,7 @@ tree_iterate_all (struct MeshTunnelTree *tree,
   struct MeshTreePendingNode *pending;
 
   cb (cb_cls, tree->root->peer, 0);
-  pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode));
+  pending = GNUNET_new (struct MeshTreePendingNode);
   pending->node = tree->root;
   head = tail = NULL;
   GNUNET_CONTAINER_DLL_insert (head, tail, pending);
@@ -661,7 +661,7 @@ tree_iterate_all (struct MeshTunnelTree *tree,
     for (n = parent->children_head; NULL != n; n = n->next)
     {
       cb (cb_cls, n->peer, parent->peer);
-      pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode));
+      pending = GNUNET_new (struct MeshTreePendingNode);
       pending->node = n;
       /* Insert_tail: breadth first, Insert: depth first */
       GNUNET_CONTAINER_DLL_insert (head, tail, pending);
@@ -742,7 +742,7 @@ tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer_id,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree:   Deleting path to %s.\n",
               GNUNET_i2s (&id));
 #endif
-  if (peer_id == t->root->peer)
+  if (NULL == t->root || peer_id == t->root->peer)
     return NULL;
 
   for (n = t->disconnected_head; NULL != n; n = n->next)
@@ -1068,7 +1068,6 @@ tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
     GNUNET_break (0);
     return GNUNET_YES;
   }
-  GNUNET_break (NULL == n->children_head);
   tree_node_destroy (n);
   if (NULL == t->root->children_head && t->me != t->root)
   {