diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-30 04:19:31 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-30 04:19:31 +0000 |
commit | 435e32448cc19283ea92aa6a45c682a36a8313b0 (patch) | |
tree | 8aac108cf516134d9bd8ffb977be0323918e8000 /src/mesh/gnunet-service-mesh-enc.c | |
parent | a8001b19370e6b7cd270d0286b7d99f1893dba34 (diff) | |
download | gnunet-435e32448cc19283ea92aa6a45c682a36a8313b0.tar.gz gnunet-435e32448cc19283ea92aa6a45c682a36a8313b0.zip |
- fix memleaks in loopback case
Diffstat (limited to 'src/mesh/gnunet-service-mesh-enc.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index 64d128ee2..f35a9b682 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -1841,6 +1841,7 @@ send_prebuilt_message_connection (const struct GNUNET_MessageHeader *message, | |||
1841 | struct GNUNET_MESH_ACK *amsg; | 1841 | struct GNUNET_MESH_ACK *amsg; |
1842 | struct GNUNET_MESH_Poll *pmsg; | 1842 | struct GNUNET_MESH_Poll *pmsg; |
1843 | struct GNUNET_MESH_ConnectionDestroy *dmsg; | 1843 | struct GNUNET_MESH_ConnectionDestroy *dmsg; |
1844 | struct GNUNET_MESH_ConnectionBroken *bmsg; | ||
1844 | uint32_t ttl; | 1845 | uint32_t ttl; |
1845 | 1846 | ||
1846 | case GNUNET_MESSAGE_TYPE_MESH_FWD: | 1847 | case GNUNET_MESSAGE_TYPE_MESH_FWD: |
@@ -1877,6 +1878,12 @@ send_prebuilt_message_connection (const struct GNUNET_MessageHeader *message, | |||
1877 | dmsg->reserved = 0; | 1878 | dmsg->reserved = 0; |
1878 | break; | 1879 | break; |
1879 | 1880 | ||
1881 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN: | ||
1882 | bmsg = (struct GNUNET_MESH_ConnectionBroken *) data; | ||
1883 | bmsg->cid = c->id; | ||
1884 | bmsg->reserved = 0; | ||
1885 | break; | ||
1886 | |||
1880 | default: | 1887 | default: |
1881 | GNUNET_break (0); | 1888 | GNUNET_break (0); |
1882 | } | 1889 | } |
@@ -2800,6 +2807,8 @@ static void | |||
2800 | peer_add_path_to_origin (struct MeshPeer *peer_info, | 2807 | peer_add_path_to_origin (struct MeshPeer *peer_info, |
2801 | struct MeshPeerPath *path, int trusted) | 2808 | struct MeshPeerPath *path, int trusted) |
2802 | { | 2809 | { |
2810 | if (NULL == path) | ||
2811 | return; | ||
2803 | path_invert (path); | 2812 | path_invert (path); |
2804 | peer_add_path (peer_info, path, trusted); | 2813 | peer_add_path (peer_info, path, trusted); |
2805 | } | 2814 | } |
@@ -4111,8 +4120,10 @@ connection_send_destroy (struct MeshConnection *c) | |||
4111 | peer2s (c->t->peer), | 4120 | peer2s (c->t->peer), |
4112 | c->id); | 4121 | c->id); |
4113 | 4122 | ||
4114 | send_prebuilt_message_connection (&msg.header, c, NULL, GNUNET_YES); | 4123 | if (GNUNET_NO == connection_is_terminal (c, GNUNET_YES)) |
4115 | send_prebuilt_message_connection (&msg.header, c, NULL, GNUNET_NO); | 4124 | send_prebuilt_message_connection (&msg.header, c, NULL, GNUNET_YES); |
4125 | if (GNUNET_NO == connection_is_terminal (c, GNUNET_NO)) | ||
4126 | send_prebuilt_message_connection (&msg.header, c, NULL, GNUNET_NO); | ||
4116 | c->destroy = GNUNET_YES; | 4127 | c->destroy = GNUNET_YES; |
4117 | } | 4128 | } |
4118 | 4129 | ||
@@ -4238,7 +4249,11 @@ tunnel_new (void) | |||
4238 | static void | 4249 | static void |
4239 | tunnel_add_connection (struct MeshTunnel2 *t, struct MeshConnection *c) | 4250 | tunnel_add_connection (struct MeshTunnel2 *t, struct MeshConnection *c) |
4240 | { | 4251 | { |
4252 | struct MeshConnection *aux; | ||
4241 | c->t = t; | 4253 | c->t = t; |
4254 | for (aux = t->connection_head; aux != NULL; aux = aux->next) | ||
4255 | if (aux == c) | ||
4256 | return; | ||
4242 | GNUNET_CONTAINER_DLL_insert_tail (t->connection_head, t->connection_tail, c); | 4257 | GNUNET_CONTAINER_DLL_insert_tail (t->connection_head, t->connection_tail, c); |
4243 | } | 4258 | } |
4244 | 4259 | ||
@@ -4690,6 +4705,13 @@ connection_broken (void *cls, | |||
4690 | int fwd; | 4705 | int fwd; |
4691 | 4706 | ||
4692 | fwd = peer == connection_get_prev_hop (c); | 4707 | fwd = peer == connection_get_prev_hop (c); |
4708 | |||
4709 | if (connection_is_terminal (c, fwd)) | ||
4710 | { | ||
4711 | /* Local shutdown: no point in iterating anymore */ | ||
4712 | connection_destroy (c); | ||
4713 | return GNUNET_NO; | ||
4714 | } | ||
4693 | connection_cancel_queues (c, !fwd); | 4715 | connection_cancel_queues (c, !fwd); |
4694 | 4716 | ||
4695 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); | 4717 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); |
@@ -4743,6 +4765,7 @@ queue_destroy (struct MeshPeerQueue *queue, int clear_cls) | |||
4743 | case GNUNET_MESSAGE_TYPE_MESH_POLL: | 4765 | case GNUNET_MESSAGE_TYPE_MESH_POLL: |
4744 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK: | 4766 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK: |
4745 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: | 4767 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: |
4768 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN: | ||
4746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " prebuilt message\n");; | 4769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " prebuilt message\n");; |
4747 | GNUNET_free_non_null (queue->cls); | 4770 | GNUNET_free_non_null (queue->cls); |
4748 | break; | 4771 | break; |
@@ -5333,42 +5356,45 @@ handle_mesh_connection_create (void *cls, | |||
5333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); | 5356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); |
5334 | c = connection_new (cid); | 5357 | c = connection_new (cid); |
5335 | if (NULL == c) | 5358 | if (NULL == c) |
5359 | return GNUNET_OK; connection_reset_timeout (c, GNUNET_YES); | ||
5360 | tunnel_change_state (c->t, MESH_TUNNEL_WAITING); | ||
5361 | |||
5362 | /* Create path */ | ||
5363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); | ||
5364 | path = path_new (size); | ||
5365 | own_pos = 0; | ||
5366 | for (i = 0; i < size; i++) | ||
5367 | { | ||
5368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", | ||
5369 | GNUNET_i2s (&id[i])); | ||
5370 | path->peers[i] = GNUNET_PEER_intern (&id[i]); | ||
5371 | if (path->peers[i] == myid) | ||
5372 | own_pos = i; | ||
5373 | } | ||
5374 | if (own_pos == 0 && path->peers[own_pos] != myid) | ||
5375 | { | ||
5376 | /* create path: self not found in path through self */ | ||
5377 | GNUNET_break_op (0); | ||
5378 | path_destroy (path); | ||
5379 | connection_destroy (c); | ||
5336 | return GNUNET_OK; | 5380 | return GNUNET_OK; |
5381 | } | ||
5382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | ||
5383 | path_add_to_peers (path, GNUNET_NO); | ||
5384 | c->path = path_duplicate (path); | ||
5385 | c->own_pos = own_pos; | ||
5386 | } | ||
5387 | else | ||
5388 | { | ||
5389 | path = NULL; | ||
5337 | } | 5390 | } |
5338 | connection_reset_timeout (c, GNUNET_YES); | ||
5339 | tunnel_change_state (c->t, MESH_TUNNEL_WAITING); | ||
5340 | 5391 | ||
5341 | /* Remember peers */ | 5392 | /* Remember peers */ |
5342 | dest_peer = peer_get (&id[size - 1]); | 5393 | dest_peer = peer_get (&id[size - 1]); |
5343 | orig_peer = peer_get (&id[0]); | 5394 | orig_peer = peer_get (&id[0]); |
5344 | 5395 | ||
5345 | /* Create path */ | ||
5346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); | ||
5347 | path = path_new (size); | ||
5348 | own_pos = 0; | ||
5349 | for (i = 0; i < size; i++) | ||
5350 | { | ||
5351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", | ||
5352 | GNUNET_i2s (&id[i])); | ||
5353 | path->peers[i] = GNUNET_PEER_intern (&id[i]); | ||
5354 | if (path->peers[i] == myid) | ||
5355 | own_pos = i; | ||
5356 | } | ||
5357 | if (own_pos == 0 && path->peers[own_pos] != myid) | ||
5358 | { | ||
5359 | /* create path: self not found in path through self */ | ||
5360 | GNUNET_break_op (0); | ||
5361 | path_destroy (path); | ||
5362 | connection_destroy (c); | ||
5363 | return GNUNET_OK; | ||
5364 | } | ||
5365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | ||
5366 | path_add_to_peers (path, GNUNET_NO); | ||
5367 | c->path = path_duplicate (path); | ||
5368 | c->own_pos = own_pos; | ||
5369 | |||
5370 | /* Is it a connection to us? */ | 5396 | /* Is it a connection to us? */ |
5371 | if (own_pos == size - 1) | 5397 | if (c->own_pos == size - 1) |
5372 | { | 5398 | { |
5373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); | 5399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); |
5374 | peer_add_path_to_origin (orig_peer, path, GNUNET_YES); | 5400 | peer_add_path_to_origin (orig_peer, path, GNUNET_YES); |