From 8790a0dbeae9be48306661f9639931b6cb5d6632 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Tue, 26 Jun 2018 15:00:42 +0200 Subject: [PATCH] fix several memory leaks --- src/rps/gnunet-service-rps.c | 108 +++++++++++++------------ src/rps/gnunet-service-rps_custommap.c | 1 + src/rps/gnunet-service-rps_sampler.c | 1 + src/rps/rps-test_util.c | 6 +- src/util/common_allocation.c | 1 + src/util/disk.c | 1 + 6 files changed, 63 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) return ret; } +static void +remove_pending_message (struct PendingMessage *pending_msg, int cancel); /** * @brief Set the peer flag to living and @@ -531,7 +533,7 @@ set_peer_live (struct PeerContext *peer_ctx) GNUNET_i2s (&peer_ctx->peer_id)); // TODO wait until cadet sets mq->cancel_impl //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); - GNUNET_free (peer_ctx->liveliness_check_pending); + remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); peer_ctx->liveliness_check_pending = NULL; } @@ -653,56 +655,6 @@ get_mq (const struct GNUNET_PeerIdentity *peer) return peer_ctx->mq; } - -/** - * @brief This is called in response to the first message we sent as a - * liveliness check. - * - * @param cls #PeerContext of peer with pending liveliness check - */ -static void -mq_liveliness_check_successful (void *cls) -{ - struct PeerContext *peer_ctx = cls; - - if (NULL != peer_ctx->liveliness_check_pending) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Liveliness check for peer %s was successfull\n", - GNUNET_i2s (&peer_ctx->peer_id)); - GNUNET_free (peer_ctx->liveliness_check_pending); - peer_ctx->liveliness_check_pending = NULL; - set_peer_live (peer_ctx); - } -} - -/** - * Issue a check whether peer is live - * - * @param peer_ctx the context of the peer - */ -static void -check_peer_live (struct PeerContext *peer_ctx) -{ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Get informed about peer %s getting live\n", - GNUNET_i2s (&peer_ctx->peer_id)); - - struct GNUNET_MQ_Handle *mq; - struct GNUNET_MQ_Envelope *ev; - - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); - peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); - peer_ctx->liveliness_check_pending->ev = ev; - peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; - peer_ctx->liveliness_check_pending->type = "Check liveliness"; - mq = get_mq (&peer_ctx->peer_id); - GNUNET_MQ_notify_sent (ev, - mq_liveliness_check_successful, - peer_ctx); - GNUNET_MQ_send (mq, ev); -} - /** * @brief Add an envelope to a message passed to mq to list of pending messages * @@ -756,6 +708,59 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel) } +/** + * @brief This is called in response to the first message we sent as a + * liveliness check. + * + * @param cls #PeerContext of peer with pending liveliness check + */ +static void +mq_liveliness_check_successful (void *cls) +{ + struct PeerContext *peer_ctx = cls; + + if (NULL != peer_ctx->liveliness_check_pending) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Liveliness check for peer %s was successfull\n", + GNUNET_i2s (&peer_ctx->peer_id)); + //GNUNET_free (peer_ctx->liveliness_check_pending); + remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); + peer_ctx->liveliness_check_pending = NULL; + set_peer_live (peer_ctx); + } +} + +/** + * Issue a check whether peer is live + * + * @param peer_ctx the context of the peer + */ +static void +check_peer_live (struct PeerContext *peer_ctx) +{ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Get informed about peer %s getting live\n", + GNUNET_i2s (&peer_ctx->peer_id)); + + struct GNUNET_MQ_Handle *mq; + struct GNUNET_MQ_Envelope *ev; + + ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); + //peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); + //peer_ctx->liveliness_check_pending->ev = ev; + //peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; + //peer_ctx->liveliness_check_pending->type = "Check liveliness"; + peer_ctx->liveliness_check_pending = + insert_pending_message (&peer_ctx->peer_id, ev, "Check liveliness"); + mq = get_mq (&peer_ctx->peer_id); + GNUNET_MQ_notify_sent (ev, + mq_liveliness_check_successful, + peer_ctx); + GNUNET_MQ_send (mq, ev); +} + + /** * @brief Check whether function of type #PeerOp was already scheduled * @@ -2893,7 +2898,6 @@ client_respond (void *cls, GNUNET_memcpy (&out_msg[1], peer_ids, num_peers * sizeof (struct GNUNET_PeerIdentity)); - GNUNET_free (peer_ids); cli_ctx = reply_cls->cli_ctx; 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, GNUNET_free (index); GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); + GNUNET_free (p); return GNUNET_OK; } 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) } GNUNET_free (i); } + GNUNET_free (req_handle->ids); GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, req_handle->sampler->req_handle_tail, 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) if (NULL == strstr (name, "sampler_el")) {/* only append random string to sampler */ if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) - LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); + LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); - GNUNET_free (name_buf); - return file_name; + GNUNET_free (name_buf); + return file_name; } return name_buf; diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 53e1a6707..fc7953df2 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -486,6 +486,7 @@ GNUNET_asprintf (char **buf, *buf = GNUNET_malloc (ret + 1); va_start (args, format); ret = VSPRINTF (*buf, format, args); + GNUNET_free (buf); va_end (args); return ret; } diff --git a/src/util/disk.c b/src/util/disk.c index e0227be70..26b615df9 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -605,6 +605,7 @@ GNUNET_DISK_mktemp (const char *t) umask (omask); if (0 != CLOSE (fd)) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn); + GNUNET_free (fn); return fn; } -- 2.25.1