aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2023-02-07 17:25:49 +0100
committert3sserakt <t3ss@posteo.de>2023-02-07 17:25:49 +0100
commitfb61e1a7a5fbd7b8f696dd7b66b15ae7c35f9013 (patch)
tree194fe008710f9d4e767c1715a28137d0442f6326
parent54638eb127fa967972bdbc7e887f12948d037409 (diff)
downloadgnunet-fb61e1a7a5fbd7b8f696dd7b66b15ae7c35f9013.tar.gz
gnunet-fb61e1a7a5fbd7b8f696dd7b66b15ae7c35f9013.zip
Fixed #7630: Memory leak in (?) finish_test in testing_api_loop.c
-rw-r--r--src/testing/testing.h9
-rw-r--r--src/testing/testing_api_cmd_barrier.c1
-rw-r--r--src/testing/testing_api_cmd_netjail_start_cmds_helper.c1
-rw-r--r--src/testing/testing_api_loop.c151
4 files changed, 76 insertions, 86 deletions
diff --git a/src/testing/testing.h b/src/testing/testing.h
index adcb50a13..fbd7d0d34 100644
--- a/src/testing/testing.h
+++ b/src/testing/testing.h
@@ -327,15 +327,6 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier,
327 327
328 328
329/** 329/**
330 * Deleting all barriers create in the context of this interpreter.
331 *
332 * @param is The interpreter.
333 */
334void
335TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is);
336
337
338/**
339 * Getting a barrier from the interpreter. 330 * Getting a barrier from the interpreter.
340 * 331 *
341 * @param is The interpreter. 332 * @param is The interpreter.
diff --git a/src/testing/testing_api_cmd_barrier.c b/src/testing/testing_api_cmd_barrier.c
index 118918bc4..9dd154059 100644
--- a/src/testing/testing_api_cmd_barrier.c
+++ b/src/testing/testing_api_cmd_barrier.c
@@ -141,7 +141,6 @@ barrier_cleanup (void *cls)
141{ 141{
142 struct BarrierState *brs = cls; 142 struct BarrierState *brs = cls;
143 143
144 GNUNET_free (brs->barrier);
145 GNUNET_free (brs); 144 GNUNET_free (brs);
146} 145}
147 146
diff --git a/src/testing/testing_api_cmd_netjail_start_cmds_helper.c b/src/testing/testing_api_cmd_netjail_start_cmds_helper.c
index 619392119..f1ef9fef1 100644
--- a/src/testing/testing_api_cmd_netjail_start_cmds_helper.c
+++ b/src/testing/testing_api_cmd_netjail_start_cmds_helper.c
@@ -217,7 +217,6 @@ static void
217netjail_exec_cleanup (void *cls) 217netjail_exec_cleanup (void *cls)
218{ 218{
219 struct NetJailState *ns = cls; 219 struct NetJailState *ns = cls;
220 TST_interpreter_delete_barriers (ns->is);
221 GNUNET_free (ns); 220 GNUNET_free (ns);
222} 221}
223 222
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 7d719afc0..3ff7d2957 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -239,6 +239,81 @@ GNUNET_TESTING_interpreter_lookup_command_all (
239} 239}
240 240
241 241
242int
243free_barrier_node_cb (void *cls,
244 const struct GNUNET_ShortHashCode *key,
245 void *value)
246{
247 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls;
248 struct GNUNET_TESTING_NetjailNode *node = value;
249 struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier;
250 struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is;
251
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "free_barrier_node_cb\n");
254 if (GNUNET_NO == is->finishing)
255 {
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "TST_interpreter_send_barrier_crossable\n");
258 TST_interpreter_send_barrier_crossable (is,
259 barrier->name,
260 node->node_number);
261 }
262 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (
263 barrier->nodes, key, node));
264 return GNUNET_YES;
265}
266
267
268int
269free_barriers_cb (void *cls,
270 const struct GNUNET_ShortHashCode *key,
271 void *value)
272{
273 struct GNUNET_TESTING_Interpreter *is = cls;
274 struct GNUNET_TESTING_Barrier *barrier = value;
275 struct CommandListEntry *pos;
276 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
277
278 if (NULL != barrier->nodes)
279 {
280 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
281 free_barrier_node_cb_cls->barrier = barrier;
282 free_barrier_node_cb_cls->is = is;
283 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
284 free_barrier_node_cb,
285 free_barrier_node_cb_cls);
286 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
287 barrier->nodes = NULL;
288 }
289
290 while (NULL != (pos = barrier->cmds_head))
291 {
292 GNUNET_CONTAINER_DLL_remove (barrier->cmds_head,
293 barrier->cmds_tail,
294 pos);
295 GNUNET_free (pos);
296 }
297 GNUNET_free (barrier);
298 return GNUNET_YES;
299}
300
301
302/**
303 * Deleting all barriers create in the context of this interpreter.
304 *
305 * @param is The interpreter.
306 */
307static void
308interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
309{
310 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
311 free_barriers_cb,
312 is);
313 GNUNET_CONTAINER_multishortmap_destroy (is->barriers);
314}
315
316
242/** 317/**
243 * Finish the test run, return the final result. 318 * Finish the test run, return the final result.
244 * 319 *
@@ -285,6 +360,7 @@ finish_test (void *cls)
285 GNUNET_free (is->commands); 360 GNUNET_free (is->commands);
286 is->rc (is->rc_cls, 361 is->rc (is->rc_cls,
287 is->result); 362 is->result);
363 interpreter_delete_barriers (is);
288 GNUNET_free (is->helper); 364 GNUNET_free (is->helper);
289 GNUNET_free (is); 365 GNUNET_free (is);
290} 366}
@@ -687,32 +763,6 @@ TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
687} 763}
688 764
689 765
690int
691free_barrier_node_cb (void *cls,
692 const struct GNUNET_ShortHashCode *key,
693 void *value)
694{
695 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls;
696 struct GNUNET_TESTING_NetjailNode *node = value;
697 struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier;
698 struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is;
699
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
701 "free_barrier_node_cb\n");
702 if (GNUNET_NO == is->finishing)
703 {
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705 "TST_interpreter_send_barrier_crossable\n");
706 TST_interpreter_send_barrier_crossable (is,
707 barrier->name,
708 node->node_number);
709 }
710 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (
711 barrier->nodes, key, node));
712 return GNUNET_YES;
713}
714
715
716/** 766/**
717 * Getting a barrier from the interpreter. 767 * Getting a barrier from the interpreter.
718 * 768 *
@@ -797,55 +847,6 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
797} 847}
798 848
799 849
800int
801free_barriers_cb (void *cls,
802 const struct GNUNET_ShortHashCode *key,
803 void *value)
804{
805 struct GNUNET_TESTING_Interpreter *is = cls;
806 struct GNUNET_TESTING_Barrier *barrier = value;
807 struct CommandListEntry *pos;
808 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
809
810 if (NULL != barrier->nodes)
811 {
812 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
813 free_barrier_node_cb_cls->barrier = barrier;
814 free_barrier_node_cb_cls->is = is;
815 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
816 free_barrier_node_cb,
817 free_barrier_node_cb_cls);
818 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
819 barrier->nodes = NULL;
820 }
821
822 while (NULL != (pos = barrier->cmds_head))
823 {
824 GNUNET_CONTAINER_DLL_remove (barrier->cmds_head,
825 barrier->cmds_tail,
826 pos);
827 GNUNET_free (pos);
828 }
829 GNUNET_free (barrier);
830 return GNUNET_YES;
831}
832
833
834/**
835 * Deleting all barriers create in the context of this interpreter.
836 *
837 * @param is The interpreter.
838 */
839void
840TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
841{
842 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
843 free_barriers_cb,
844 is);
845 GNUNET_CONTAINER_multishortmap_destroy (is->barriers);
846}
847
848
849/** 850/**
850 * Add a barrier to the loop. 851 * Add a barrier to the loop.
851 * 852 *