summaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-06-26 15:00:42 +0200
committerJulius Bünger <buenger@mytum.de>2018-06-26 15:00:42 +0200
commit8790a0dbeae9be48306661f9639931b6cb5d6632 (patch)
treef85df3c8100ed0b799da78ffc51e11c1a0801026 /src/rps
parent52b006735e61d184281b56094758ecdc7355ed84 (diff)
fix several memory leaks
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c108
-rw-r--r--src/rps/gnunet-service-rps_custommap.c1
-rw-r--r--src/rps/gnunet-service-rps_sampler.c1
-rw-r--r--src/rps/rps-test_util.c6
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)
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
*
@@ -757,6 +709,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
*
* The array with pending operations will probably never grow really big, so
@@ -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;