diff options
author | Julius Bünger <buenger@mytum.de> | 2018-06-26 15:00:42 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-06-26 15:00:42 +0200 |
commit | 8790a0dbeae9be48306661f9639931b6cb5d6632 (patch) | |
tree | f85df3c8100ed0b799da78ffc51e11c1a0801026 /src/rps/gnunet-service-rps.c | |
parent | 52b006735e61d184281b56094758ecdc7355ed84 (diff) | |
download | gnunet-8790a0dbeae9be48306661f9639931b6cb5d6632.tar.gz gnunet-8790a0dbeae9be48306661f9639931b6cb5d6632.zip |
fix several memory leaks
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 108 |
1 files changed, 56 insertions, 52 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 06adec8b5..33d4e4fc3 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -503,6 +503,8 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer) | |||
503 | return ret; | 503 | return ret; |
504 | } | 504 | } |
505 | 505 | ||
506 | static void | ||
507 | remove_pending_message (struct PendingMessage *pending_msg, int cancel); | ||
506 | 508 | ||
507 | /** | 509 | /** |
508 | * @brief Set the peer flag to living and | 510 | * @brief Set the peer flag to living and |
@@ -531,7 +533,7 @@ set_peer_live (struct PeerContext *peer_ctx) | |||
531 | GNUNET_i2s (&peer_ctx->peer_id)); | 533 | GNUNET_i2s (&peer_ctx->peer_id)); |
532 | // TODO wait until cadet sets mq->cancel_impl | 534 | // TODO wait until cadet sets mq->cancel_impl |
533 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | 535 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); |
534 | GNUNET_free (peer_ctx->liveliness_check_pending); | 536 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); |
535 | peer_ctx->liveliness_check_pending = NULL; | 537 | peer_ctx->liveliness_check_pending = NULL; |
536 | } | 538 | } |
537 | 539 | ||
@@ -653,56 +655,6 @@ get_mq (const struct GNUNET_PeerIdentity *peer) | |||
653 | return peer_ctx->mq; | 655 | return peer_ctx->mq; |
654 | } | 656 | } |
655 | 657 | ||
656 | |||
657 | /** | ||
658 | * @brief This is called in response to the first message we sent as a | ||
659 | * liveliness check. | ||
660 | * | ||
661 | * @param cls #PeerContext of peer with pending liveliness check | ||
662 | */ | ||
663 | static void | ||
664 | mq_liveliness_check_successful (void *cls) | ||
665 | { | ||
666 | struct PeerContext *peer_ctx = cls; | ||
667 | |||
668 | if (NULL != peer_ctx->liveliness_check_pending) | ||
669 | { | ||
670 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
671 | "Liveliness check for peer %s was successfull\n", | ||
672 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
673 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
674 | peer_ctx->liveliness_check_pending = NULL; | ||
675 | set_peer_live (peer_ctx); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * Issue a check whether peer is live | ||
681 | * | ||
682 | * @param peer_ctx the context of the peer | ||
683 | */ | ||
684 | static void | ||
685 | check_peer_live (struct PeerContext *peer_ctx) | ||
686 | { | ||
687 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
688 | "Get informed about peer %s getting live\n", | ||
689 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
690 | |||
691 | struct GNUNET_MQ_Handle *mq; | ||
692 | struct GNUNET_MQ_Envelope *ev; | ||
693 | |||
694 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
695 | peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); | ||
696 | peer_ctx->liveliness_check_pending->ev = ev; | ||
697 | peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; | ||
698 | peer_ctx->liveliness_check_pending->type = "Check liveliness"; | ||
699 | mq = get_mq (&peer_ctx->peer_id); | ||
700 | GNUNET_MQ_notify_sent (ev, | ||
701 | mq_liveliness_check_successful, | ||
702 | peer_ctx); | ||
703 | GNUNET_MQ_send (mq, ev); | ||
704 | } | ||
705 | |||
706 | /** | 658 | /** |
707 | * @brief Add an envelope to a message passed to mq to list of pending messages | 659 | * @brief Add an envelope to a message passed to mq to list of pending messages |
708 | * | 660 | * |
@@ -757,6 +709,59 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel) | |||
757 | 709 | ||
758 | 710 | ||
759 | /** | 711 | /** |
712 | * @brief This is called in response to the first message we sent as a | ||
713 | * liveliness check. | ||
714 | * | ||
715 | * @param cls #PeerContext of peer with pending liveliness check | ||
716 | */ | ||
717 | static void | ||
718 | mq_liveliness_check_successful (void *cls) | ||
719 | { | ||
720 | struct PeerContext *peer_ctx = cls; | ||
721 | |||
722 | if (NULL != peer_ctx->liveliness_check_pending) | ||
723 | { | ||
724 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
725 | "Liveliness check for peer %s was successfull\n", | ||
726 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
727 | //GNUNET_free (peer_ctx->liveliness_check_pending); | ||
728 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); | ||
729 | peer_ctx->liveliness_check_pending = NULL; | ||
730 | set_peer_live (peer_ctx); | ||
731 | } | ||
732 | } | ||
733 | |||
734 | /** | ||
735 | * Issue a check whether peer is live | ||
736 | * | ||
737 | * @param peer_ctx the context of the peer | ||
738 | */ | ||
739 | static void | ||
740 | check_peer_live (struct PeerContext *peer_ctx) | ||
741 | { | ||
742 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
743 | "Get informed about peer %s getting live\n", | ||
744 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
745 | |||
746 | struct GNUNET_MQ_Handle *mq; | ||
747 | struct GNUNET_MQ_Envelope *ev; | ||
748 | |||
749 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
750 | //peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); | ||
751 | //peer_ctx->liveliness_check_pending->ev = ev; | ||
752 | //peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; | ||
753 | //peer_ctx->liveliness_check_pending->type = "Check liveliness"; | ||
754 | peer_ctx->liveliness_check_pending = | ||
755 | insert_pending_message (&peer_ctx->peer_id, ev, "Check liveliness"); | ||
756 | mq = get_mq (&peer_ctx->peer_id); | ||
757 | GNUNET_MQ_notify_sent (ev, | ||
758 | mq_liveliness_check_successful, | ||
759 | peer_ctx); | ||
760 | GNUNET_MQ_send (mq, ev); | ||
761 | } | ||
762 | |||
763 | |||
764 | /** | ||
760 | * @brief Check whether function of type #PeerOp was already scheduled | 765 | * @brief Check whether function of type #PeerOp was already scheduled |
761 | * | 766 | * |
762 | * The array with pending operations will probably never grow really big, so | 767 | * The array with pending operations will probably never grow really big, so |
@@ -2893,7 +2898,6 @@ client_respond (void *cls, | |||
2893 | GNUNET_memcpy (&out_msg[1], | 2898 | GNUNET_memcpy (&out_msg[1], |
2894 | peer_ids, | 2899 | peer_ids, |
2895 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 2900 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
2896 | GNUNET_free (peer_ids); | ||
2897 | 2901 | ||
2898 | cli_ctx = reply_cls->cli_ctx; | 2902 | cli_ctx = reply_cls->cli_ctx; |
2899 | GNUNET_assert (NULL != cli_ctx); | 2903 | GNUNET_assert (NULL != cli_ctx); |