From 95cac55800e8f7b4e59a03d5acefb200b20ab3c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Tue, 6 Sep 2016 14:05:44 +0000 Subject: [PATCH] -rps: proper destruction of sampler elements --- src/rps/gnunet-service-rps_sampler.c | 2 +- src/rps/gnunet-service-rps_sampler_elem.c | 22 ++++++++++++++++++++++ src/rps/gnunet-service-rps_sampler_elem.h | 9 +++++++++ src/rps/test_rps.c | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index 95aabc21a..cfc5ce77b 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c @@ -327,7 +327,7 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) "-%" PRIu32 ": %s", i, sampler->sampler_elements[i]->file_name); - GNUNET_free (sampler->sampler_elements[i]); + RPS_sampler_elem_destroy (sampler->sampler_elements[i]); } GNUNET_array_grow (sampler->sampler_elements, diff --git a/src/rps/gnunet-service-rps_sampler_elem.c b/src/rps/gnunet-service-rps_sampler_elem.c index c22ed564b..007f818e2 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.c +++ b/src/rps/gnunet-service-rps_sampler_elem.c @@ -98,6 +98,24 @@ RPS_sampler_elem_create (void) } +/** + * Destroy a sampler element. + * + * @param sampler_elem the element to destroy + */ +void +RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem) +{ + #ifdef TO_FILE + if (NULL != sampler_elem->file_name) + { + GNUNET_free (sampler_elem->file_name); + } + #endif /* TO_FILE */ + GNUNET_free (sampler_elem); +} + + /** * Input an PeerID into the given sampler element. * @@ -112,9 +130,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, s_elem->num_peers++; + #ifdef TO_FILE to_file (s_elem->file_name, "Got id %s", GNUNET_i2s_full (other)); + #endif /* TO_FILE */ if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) { @@ -155,9 +175,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, } s_elem->is_empty = NOT_EMPTY; + #ifdef TO_FILE to_file (s_elem->file_name, "Now holding %s", GNUNET_i2s_full (&s_elem->peer_id)); + #endif /* TO_FILE */ } /** diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h index 861a579bc..bbf2c147b 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.h +++ b/src/rps/gnunet-service-rps_sampler_elem.h @@ -119,6 +119,15 @@ struct RPS_SamplerElement * RPS_sampler_elem_create (void); +/** + * Destroy a sampler element. + * + * @param sampler_elem the element to destroy + */ +void +RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem); + + /** * Input an PeerID into the given sampler element. * diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index e0fbdbb88..629b73d44 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c @@ -1292,6 +1292,7 @@ file_name_cb (void *cls, const char *filename) { RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); } + RPS_sampler_elem_destroy (s_elem); } return GNUNET_OK; } -- 2.25.1