[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r16996 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r16996 - gnunet/src/mesh |
Date: |
Wed, 21 Sep 2011 21:51:37 +0200 |
Author: bartpolot
Date: 2011-09-21 21:51:37 +0200 (Wed, 21 Sep 2011)
New Revision: 16996
Modified:
gnunet/src/mesh/mesh_tunnel_tree.c
gnunet/src/mesh/mesh_tunnel_tree.h
gnunet/src/mesh/test_mesh_path_api.c
Log:
Fixed memory leaks
Modified: gnunet/src/mesh/mesh_tunnel_tree.c
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.c 2011-09-21 19:38:19 UTC (rev 16995)
+++ gnunet/src/mesh/mesh_tunnel_tree.c 2011-09-21 19:51:37 UTC (rev 16996)
@@ -149,24 +149,35 @@
/**
* Recusively mark peer and children as disconnected, notify client
*
+ * @param tree Tree this node belongs to
* @param parent Node to be clean, potentially with children
* @param cb Callback to use to notify about disconnected peers.
*/
void
-tree_mark_peers_disconnected (struct MeshTunnelTreeNode *parent,
- MeshNodeDisconnectCB cb)
+tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
+ struct MeshTunnelTreeNode *parent,
+ MeshNodeDisconnectCB cb)
{
+ struct GNUNET_PeerIdentity *pi;
+ struct GNUNET_PeerIdentity id;
unsigned int i;
+ for (i = 0; i < parent->nchildren; i++)
+ {
+ tree_mark_peers_disconnected (tree, &parent->children[i], cb);
+ }
if (MESH_PEER_READY == parent->status)
{
cb (parent);
}
parent->status = MESH_PEER_RECONNECTING;
- for (i = 0; i < parent->nchildren; i++)
- {
- tree_mark_peers_disconnected (&parent->children[i], cb);
- }
+
+ /* Remove and free info about first hop */
+ GNUNET_PEER_resolve(parent->peer, &id);
+ pi = GNUNET_CONTAINER_multihashmap_get(tree->first_hops, &id.hashPubKey);
+ GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey);
+ if (NULL != pi)
+ GNUNET_free(pi);
// struct GNUNET_MESH_PeerControl msg;
// if (NULL == parent->t->client)
// return;
@@ -202,27 +213,31 @@
struct MeshTunnelTreeNode *node;
struct MeshTunnelTreeNode *n;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting path to %u.\n", peer_id);
if (peer_id == t->root->peer)
return NULL;
- node = n = tree_find_peer (t->me, peer_id);
+ n = tree_find_peer (t->me, peer_id);
if (NULL == n)
return NULL;
+ node = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode));
+ *node = *n;
parent = n->parent;
+ parent->nchildren--;
n->parent = NULL;
- while (NULL != parent && MESH_PEER_RELAY == parent->status &&
- 1 == parent->nchildren)
+ *n = parent->children[parent->nchildren];
+ parent->children = GNUNET_realloc(parent->children,
+ parent->nchildren
+ * sizeof(struct MeshTunnelTreeNode));
+ while (t->root != parent && MESH_PEER_RELAY == parent->status &&
+ 0 == parent->nchildren)
{
- n = parent;
- GNUNET_free (parent->children);
- parent = parent->parent;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting node %u.\n", parent->peer);
+ n = parent->parent;
+ tree_node_destroy(parent);
+ parent = n;
}
- if (NULL == parent)
- return node;
- *n = parent->children[parent->nchildren - 1];
- parent->nchildren--;
- parent->children = GNUNET_realloc (parent->children, parent->nchildren);
- tree_mark_peers_disconnected (node, cb);
+ tree_mark_peers_disconnected (t, node, cb);
return node;
}
@@ -294,7 +309,7 @@
unsigned int j;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Adding path [%u] towards peer %u to peer %u.\n",
+ "Adding path [%u] towards peer %u to peer %u.\n",
p->length,
p->peers[p->length - 1],
t->me->peer);
@@ -318,17 +333,13 @@
for (i = 1; i < p->length; i++)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Looking for peer %u.\n",
+ "Looking for peer %u.\n",
p->peers[i]);
parent = n;
if (p->peers[i] == myid)
me = i;
for (j = 0; j < n->nchildren; j++)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Child %u. is %u\n",
- j,
- n->children[j].peer);
if (n->children[j].peer == p->peers[i])
{
n = &n->children[j];
@@ -341,7 +352,7 @@
break;
}
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: All childen visited.\n");
+ "All childen visited.\n");
if (-1 == me)
{
/* New path deviates from tree before reaching us. What happened? */
@@ -352,32 +363,28 @@
while (i < p->length)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Adding peer %u, to %u.\n",
+ "Adding peer %u, to %u.\n",
p->peers[i],
parent->peer);
parent->nchildren++;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: realloc %p, %u\n", parent->children,
- parent->nchildren *
- sizeof(struct MeshTunnelTreeNode));
parent->children = GNUNET_realloc (parent->children,
parent->nchildren *
sizeof(struct MeshTunnelTreeNode));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: done: %p\n", parent->children);
n = &parent->children[parent->nchildren - 1];
if (i == p->length - 1 && NULL != oldnode)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Putting old note into place.\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting old note into place.\n");
/* Assignation and free can be misleading, using explicit mempcy */
memcpy (n, oldnode, sizeof (struct MeshTunnelTreeNode));
- tree_node_destroy(oldnode);
+ GNUNET_free (oldnode);
+ for (j = 0; j < n->nchildren; j++)
+ {
+ n->children[j].parent = n;
+ }
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test: Creating new node.\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating new node.\n");
n->t = t->t;
n->status = MESH_PEER_RELAY;
n->peer = p->peers[i];
@@ -394,12 +401,16 @@
if (me < p->length - 1)
{
GNUNET_PEER_resolve (p->peers[p->length - 1], &id);
+ hop = GNUNET_CONTAINER_multihashmap_get(t->first_hops, &id.hashPubKey);
+ if (NULL != hop)
+ GNUNET_free(hop);
hop = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
GNUNET_PEER_resolve (p->peers[me + 1], hop);
GNUNET_CONTAINER_multihashmap_put (t->first_hops, &id.hashPubKey,
hop,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
}
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New node added.\n");
return GNUNET_OK;
}
@@ -412,14 +423,29 @@
void
tree_node_destroy (struct MeshTunnelTreeNode *n)
{
+ struct MeshTunnelTreeNode *parent;
unsigned int i;
- if (n->nchildren == 0) return;
- for (i = 0; i < n->nchildren; i++)
+ if (n->nchildren != 0)
{
- tree_node_destroy(&n->children[i]);
+ for (i = 0; i < n->nchildren; i++)
+ {
+ tree_node_destroy(&n->children[i]);
+ }
+ if (n->children != NULL)
+ GNUNET_free(n->children);
}
- GNUNET_free(n->children);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying node %u.\n", n->peer);
+ if (NULL == (parent = n->parent))
+ return;
+ i = (n - parent->children) / sizeof(struct MeshTunnelTreeNode);
+ parent->children[i] = parent->children[parent->nchildren - 1];
+ parent->nchildren--;
+ parent->children = realloc(parent->children,
+ parent->nchildren
+ * sizeof(struct MeshTunnelTreeNode));
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroyed.\n");
}
Modified: gnunet/src/mesh/mesh_tunnel_tree.h
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.h 2011-09-21 19:38:19 UTC (rev 16995)
+++ gnunet/src/mesh/mesh_tunnel_tree.h 2011-09-21 19:51:37 UTC (rev 16996)
@@ -119,7 +119,7 @@
/**
* Cache of all peers and the first hop to them.
- * Indexed by Peer_Identity, contains a pointer to the PeerIdentity
+ * Indexed by PeerIdentity, contains a pointer to the PeerIdentity
* of 1st hop.
*/
struct GNUNET_CONTAINER_MultiHashMap *first_hops;
@@ -214,12 +214,14 @@
/**
* Recusively mark peer and children as disconnected, notify client
*
+ * @param tree Tree this node belongs to
* @param parent Node to be clean, potentially with children
* @param cb Callback to use to notify about disconnected peers
*/
void
-tree_mark_peers_disconnected (struct MeshTunnelTreeNode *parent,
- MeshNodeDisconnectCB cb);
+tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
+ struct MeshTunnelTreeNode *parent,
+ MeshNodeDisconnectCB cb);
/**
Modified: gnunet/src/mesh/test_mesh_path_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_path_api.c 2011-09-21 19:38:19 UTC (rev
16995)
+++ gnunet/src/mesh/test_mesh_path_api.c 2011-09-21 19:51:37 UTC (rev
16996)
@@ -42,7 +42,7 @@
void
cb (const struct MeshTunnelTreeNode *n)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Desconnected %u\n", n->peer);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Disconnected %u\n", n->peer);
if(0 == cb_call)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
@@ -118,7 +118,6 @@
path->length = 4;
tree_add_path(tree, path, &cb);
- finish();
path1 = tree_get_path_to_peer(tree, 3);
if (path->length != path1->length ||
memcmp(path->peers, path1->peers, path->length) != 0)
@@ -138,13 +137,11 @@
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n");
failed++;
}
- node->status = MESH_PEER_READY;
if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
{
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
failed++;
}
- return 0;
node = tree_find_peer(tree->root, 2);
if (node->peer != 2)
@@ -187,7 +184,10 @@
path->length--;
tree_add_path(tree, path, &cb);
-
+ path->length++;
+ path_destroy(path);
+ finish();
+
node = tree_find_peer(tree->root, 2);
if (node->peer != 2)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r16996 - gnunet/src/mesh,
gnunet <=