From 2460efb47675feed677989a02efcc3cd3b20f35d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Mon, 21 Feb 2011 10:03:43 +0000 Subject: [PATCH] Begone foul memory leaks! --- src/vpn/gnunet-daemon-exit.c | 18 ++++++++++++++++++ src/vpn/gnunet-daemon-vpn.c | 1 + 2 files changed, 19 insertions(+) diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index e75e1e6cd..da8392ebe 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -124,6 +124,16 @@ struct udp_state */ static struct GNUNET_CONTAINER_MultiHashMap *udp_services; +/** + * Function that frees everything from a hashmap + */ +static int +free_iterate(void* cls, const GNUNET_HashCode* hash, void* value) +{ + GNUNET_free(value); + return GNUNET_YES; +} + /** * Function scheduled as very last function, cleans up after us */ @@ -131,6 +141,10 @@ static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); + GNUNET_CONTAINER_multihashmap_iterate(udp_connections, + free_iterate, + NULL); + if (mesh_handle != NULL) { GNUNET_MESH_disconnect(mesh_handle); @@ -501,6 +515,8 @@ receive_udp_service (void *cls, GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4MASK", &ipv4mask)); inet_pton(AF_INET, ipv4addr, &tmp); inet_pton(AF_INET, ipv4mask, &tmp2); + GNUNET_free(ipv4addr); + GNUNET_free(ipv4mask); /* This should be a noop */ tmp = tmp & tmp2; @@ -586,6 +602,8 @@ receive_udp_service (void *cls, GNUNET_CONTAINER_multihashmap_contains (udp_connections, &hash)) GNUNET_CONTAINER_multihashmap_put (udp_connections, &hash, state, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + else + GNUNET_free(state); (void)GNUNET_DISK_file_write(helper_handle->fh_to_helper, buf, len); return GNUNET_YES; diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 84adcd975..d22062074 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -272,6 +272,7 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not store to hashmap\n"); + GNUNET_free(value); } -- 2.25.1