aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-08-14 18:42:46 +0200
committerJulius Bünger <buenger@mytum.de>2018-08-14 18:44:09 +0200
commit0a7b0ca8e0d6a968a3b4fd495becbd44fa5ca458 (patch)
tree99fdeb9310695e4d07b78ad4f3fd6bcbea2e0dab
parent68db913bded8a0c606e33994698708e541d1aae0 (diff)
downloadgnunet-0a7b0ca8e0d6a968a3b4fd495becbd44fa5ca458.tar.gz
gnunet-0a7b0ca8e0d6a968a3b4fd495becbd44fa5ca458.zip
Destroy channel and their datastructures properly
-rw-r--r--src/rps/gnunet-service-rps.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 1f155b14f..0c0fe9076 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -261,12 +261,6 @@ struct PeersIteratorCls
261struct ChannelCtx 261struct ChannelCtx
262{ 262{
263 /** 263 /**
264 * @brief Meant to be used in a DLL
265 */
266 struct ChannelCtx *next;
267 struct ChannelCtx *prev;
268
269 /**
270 * @brief The channel itself 264 * @brief The channel itself
271 */ 265 */
272 struct GNUNET_CADET_Channel *channel; 266 struct GNUNET_CADET_Channel *channel;
@@ -634,15 +628,22 @@ remove_channel_ctx (struct ChannelCtx *channel_ctx)
634{ 628{
635 struct PeerContext *peer_ctx = channel_ctx->peer_ctx; 629 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
636 630
631 if (NULL != channel_ctx->destruction_task)
632 {
633 GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task);
634 channel_ctx->destruction_task = NULL;
635 }
636
637 GNUNET_free (channel_ctx);
638
639 if (NULL == peer_ctx) return;
637 if (channel_ctx == peer_ctx->send_channel_ctx) 640 if (channel_ctx == peer_ctx->send_channel_ctx)
638 { 641 {
639 GNUNET_free (channel_ctx);
640 peer_ctx->send_channel_ctx = NULL; 642 peer_ctx->send_channel_ctx = NULL;
641 peer_ctx->mq = NULL; 643 peer_ctx->mq = NULL;
642 } 644 }
643 else if (channel_ctx == peer_ctx->recv_channel_ctx) 645 else if (channel_ctx == peer_ctx->recv_channel_ctx)
644 { 646 {
645 GNUNET_free (channel_ctx);
646 peer_ctx->recv_channel_ctx = NULL; 647 peer_ctx->recv_channel_ctx = NULL;
647 } 648 }
648} 649}
@@ -911,12 +912,12 @@ static void
911schedule_channel_destruction (struct ChannelCtx *channel_ctx) 912schedule_channel_destruction (struct ChannelCtx *channel_ctx)
912{ 913{
913 GNUNET_assert (NULL == 914 GNUNET_assert (NULL ==
914 channel_ctx->destruction_task); 915 channel_ctx->destruction_task);
915 GNUNET_assert (NULL != 916 GNUNET_assert (NULL !=
916 channel_ctx->channel); 917 channel_ctx->channel);
917 channel_ctx->destruction_task = 918 channel_ctx->destruction_task =
918 GNUNET_SCHEDULER_add_now (&destroy_channel_cb, 919 GNUNET_SCHEDULER_add_now (&destroy_channel_cb,
919 channel_ctx); 920 channel_ctx);
920} 921}
921 922
922 923
@@ -986,12 +987,17 @@ destroy_peer (struct PeerContext *peer_ctx)
986 if (NULL != peer_ctx->send_channel_ctx) 987 if (NULL != peer_ctx->send_channel_ctx)
987 { 988 {
988 /* This is possibly called from within channel destruction */ 989 /* This is possibly called from within channel destruction */
990 peer_ctx->send_channel_ctx->peer_ctx = NULL;
989 schedule_channel_destruction (peer_ctx->send_channel_ctx); 991 schedule_channel_destruction (peer_ctx->send_channel_ctx);
992 peer_ctx->send_channel_ctx = NULL;
993 peer_ctx->mq = NULL;
990 } 994 }
991 if (NULL != peer_ctx->recv_channel_ctx) 995 if (NULL != peer_ctx->recv_channel_ctx)
992 { 996 {
993 /* This is possibly called from within channel destruction */ 997 /* This is possibly called from within channel destruction */
998 peer_ctx->recv_channel_ctx->peer_ctx = NULL;
994 schedule_channel_destruction (peer_ctx->recv_channel_ctx); 999 schedule_channel_destruction (peer_ctx->recv_channel_ctx);
1000 peer_ctx->recv_channel_ctx = NULL;
995 } 1001 }
996 1002
997 if (GNUNET_YES != 1003 if (GNUNET_YES !=
@@ -2534,18 +2540,11 @@ cleanup_destroyed_channel (void *cls,
2534 struct ChannelCtx *channel_ctx = cls; 2540 struct ChannelCtx *channel_ctx = cls;
2535 struct PeerContext *peer_ctx = channel_ctx->peer_ctx; 2541 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2536 2542
2537 // What should be done here:
2538 // * cleanup everything related to the channel
2539 // * memory
2540 // * remove peer if necessary
2541 channel_ctx->channel = NULL; 2543 channel_ctx->channel = NULL;
2542 if (peer_ctx->recv_channel_ctx == channel_ctx) 2544 remove_channel_ctx (channel_ctx);
2543 { 2545 if (NULL != peer_ctx &&
2544 remove_channel_ctx (channel_ctx); 2546 peer_ctx->send_channel_ctx == channel_ctx)
2545 }
2546 else if (peer_ctx->send_channel_ctx == channel_ctx)
2547 { 2547 {
2548 remove_channel_ctx (channel_ctx);
2549 remove_peer (&peer_ctx->peer_id); 2548 remove_peer (&peer_ctx->peer_id);
2550 } 2549 }
2551} 2550}