aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2016-09-06 14:05:44 +0000
committerJulius Bünger <buenger@mytum.de>2016-09-06 14:05:44 +0000
commit95cac55800e8f7b4e59a03d5acefb200b20ab3c1 (patch)
tree7fef7ad0c82e03b7596c0c28cf0944d16ebc8e48
parentd6d12f337d2ff7184415ebbbbe1e0d58cdda1867 (diff)
downloadgnunet-95cac55800e8f7b4e59a03d5acefb200b20ab3c1.tar.gz
gnunet-95cac55800e8f7b4e59a03d5acefb200b20ab3c1.zip
-rps: proper destruction of sampler elements
-rw-r--r--src/rps/gnunet-service-rps_sampler.c2
-rw-r--r--src/rps/gnunet-service-rps_sampler_elem.c22
-rw-r--r--src/rps/gnunet-service-rps_sampler_elem.h9
-rw-r--r--src/rps/test_rps.c1
4 files changed, 33 insertions, 1 deletions
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)
327 "-%" PRIu32 ": %s", 327 "-%" PRIu32 ": %s",
328 i, 328 i,
329 sampler->sampler_elements[i]->file_name); 329 sampler->sampler_elements[i]->file_name);
330 GNUNET_free (sampler->sampler_elements[i]); 330 RPS_sampler_elem_destroy (sampler->sampler_elements[i]);
331 } 331 }
332 332
333 GNUNET_array_grow (sampler->sampler_elements, 333 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
@@ -99,6 +99,24 @@ RPS_sampler_elem_create (void)
99 99
100 100
101/** 101/**
102 * Destroy a sampler element.
103 *
104 * @param sampler_elem the element to destroy
105 */
106void
107RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem)
108{
109 #ifdef TO_FILE
110 if (NULL != sampler_elem->file_name)
111 {
112 GNUNET_free (sampler_elem->file_name);
113 }
114 #endif /* TO_FILE */
115 GNUNET_free (sampler_elem);
116}
117
118
119/**
102 * Input an PeerID into the given sampler element. 120 * Input an PeerID into the given sampler element.
103 * 121 *
104 * @param sampler the sampler the @a s_elem belongs to. 122 * @param sampler the sampler the @a s_elem belongs to.
@@ -112,9 +130,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
112 130
113 s_elem->num_peers++; 131 s_elem->num_peers++;
114 132
133 #ifdef TO_FILE
115 to_file (s_elem->file_name, 134 to_file (s_elem->file_name,
116 "Got id %s", 135 "Got id %s",
117 GNUNET_i2s_full (other)); 136 GNUNET_i2s_full (other));
137 #endif /* TO_FILE */
118 138
119 if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) 139 if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id)))
120 { 140 {
@@ -155,9 +175,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
155 } 175 }
156 s_elem->is_empty = NOT_EMPTY; 176 s_elem->is_empty = NOT_EMPTY;
157 177
178 #ifdef TO_FILE
158 to_file (s_elem->file_name, 179 to_file (s_elem->file_name,
159 "Now holding %s", 180 "Now holding %s",
160 GNUNET_i2s_full (&s_elem->peer_id)); 181 GNUNET_i2s_full (&s_elem->peer_id));
182 #endif /* TO_FILE */
161} 183}
162 184
163/** 185/**
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
@@ -120,6 +120,15 @@ RPS_sampler_elem_create (void);
120 120
121 121
122/** 122/**
123 * Destroy a sampler element.
124 *
125 * @param sampler_elem the element to destroy
126 */
127void
128RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem);
129
130
131/**
123 * Input an PeerID into the given sampler element. 132 * Input an PeerID into the given sampler element.
124 * 133 *
125 * @param sampler the sampler the @a s_elem belongs to. 134 * @param sampler the sampler the @a s_elem belongs to.
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)
1292 { 1292 {
1293 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); 1293 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1294 } 1294 }
1295 RPS_sampler_elem_destroy (s_elem);
1295 } 1296 }
1296 return GNUNET_OK; 1297 return GNUNET_OK;
1297} 1298}