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 | |
parent | 52b006735e61d184281b56094758ecdc7355ed84 (diff) | |
download | gnunet-8790a0dbeae9be48306661f9639931b6cb5d6632.tar.gz gnunet-8790a0dbeae9be48306661f9639931b6cb5d6632.zip |
fix several memory leaks
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 108 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_custommap.c | 1 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 1 | ||||
-rw-r--r-- | src/rps/rps-test_util.c | 6 |
4 files changed, 61 insertions, 55 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); |
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c index 90177cb94..42507655b 100644 --- a/src/rps/gnunet-service-rps_custommap.c +++ b/src/rps/gnunet-service-rps_custommap.c | |||
@@ -220,6 +220,7 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
220 | GNUNET_free (index); | 220 | GNUNET_free (index); |
221 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 221 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == |
222 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 222 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); |
223 | GNUNET_free (p); | ||
223 | return GNUNET_OK; | 224 | return GNUNET_OK; |
224 | } | 225 | } |
225 | 226 | ||
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index 711d5be63..4d1ae4650 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -725,6 +725,7 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle) | |||
725 | } | 725 | } |
726 | GNUNET_free (i); | 726 | GNUNET_free (i); |
727 | } | 727 | } |
728 | GNUNET_free (req_handle->ids); | ||
728 | GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, | 729 | GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, |
729 | req_handle->sampler->req_handle_tail, | 730 | req_handle->sampler->req_handle_tail, |
730 | req_handle); | 731 | req_handle); |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 0ee290e67..d47e4952f 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -352,10 +352,10 @@ create_file (const char *name) | |||
352 | if (NULL == strstr (name, "sampler_el")) | 352 | if (NULL == strstr (name, "sampler_el")) |
353 | {/* only append random string to sampler */ | 353 | {/* only append random string to sampler */ |
354 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) | 354 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) |
355 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | 355 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); |
356 | 356 | ||
357 | GNUNET_free (name_buf); | 357 | GNUNET_free (name_buf); |
358 | return file_name; | 358 | return file_name; |
359 | } | 359 | } |
360 | 360 | ||
361 | return name_buf; | 361 | return name_buf; |