Fixed a memory leak
authorBart Polot <bart@net.in.tum.de>
Fri, 28 Oct 2011 16:41:02 +0000 (16:41 +0000)
committerBart Polot <bart@net.in.tum.de>
Fri, 28 Oct 2011 16:41:02 +0000 (16:41 +0000)
src/mesh/mesh_tunnel_tree.c

index c58260601caf4e66bd373bb29ae4e0fcf37f4f7b..a01ff2ca7ee8365e16d119f1373964a9174d2e09 100644 (file)
@@ -403,14 +403,17 @@ tree_update_first_hops (struct MeshTunnelTree *tree,
     hop = &pi;
     GNUNET_PEER_resolve(old->peer, hop);
   }
-  copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
-  *copy = *hop;
   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 = *hop;
+
   GNUNET_CONTAINER_multihashmap_put(
     tree->first_hops,
     &id.hashPubKey,
     copy,
-    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+    GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
 
   for (n = parent->children_head; NULL != n; n = n->next)
   {