diff options
author | t3sserakt <t3ss@posteo.de> | 2023-02-07 17:25:49 +0100 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2023-02-07 17:25:49 +0100 |
commit | fb61e1a7a5fbd7b8f696dd7b66b15ae7c35f9013 (patch) | |
tree | 194fe008710f9d4e767c1715a28137d0442f6326 | |
parent | 54638eb127fa967972bdbc7e887f12948d037409 (diff) |
Fixed #7630: Memory leak in (?) finish_test in testing_api_loop.c
-rw-r--r-- | src/testing/testing.h | 9 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_barrier.c | 1 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_netjail_start_cmds_helper.c | 1 | ||||
-rw-r--r-- | src/testing/testing_api_loop.c | 151 |
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, /** - * Deleting all barriers create in the context of this interpreter. - * - * @param is The interpreter. - */ -void -TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is); - - -/** * Getting a barrier from the interpreter. * * @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) { struct BarrierState *brs = cls; - GNUNET_free (brs->barrier); GNUNET_free (brs); } 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 netjail_exec_cleanup (void *cls) { struct NetJailState *ns = cls; - TST_interpreter_delete_barriers (ns->is); GNUNET_free (ns); } 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 ( } +int +free_barrier_node_cb (void *cls, + const struct GNUNET_ShortHashCode *key, + void *value) +{ + struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls; + struct GNUNET_TESTING_NetjailNode *node = value; + struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier; + struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "free_barrier_node_cb\n"); + if (GNUNET_NO == is->finishing) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "TST_interpreter_send_barrier_crossable\n"); + TST_interpreter_send_barrier_crossable (is, + barrier->name, + node->node_number); + } + GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove ( + barrier->nodes, key, node)); + return GNUNET_YES; +} + + +int +free_barriers_cb (void *cls, + const struct GNUNET_ShortHashCode *key, + void *value) +{ + struct GNUNET_TESTING_Interpreter *is = cls; + struct GNUNET_TESTING_Barrier *barrier = value; + struct CommandListEntry *pos; + struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; + + if (NULL != barrier->nodes) + { + free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); + free_barrier_node_cb_cls->barrier = barrier; + free_barrier_node_cb_cls->is = is; + GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, + free_barrier_node_cb, + free_barrier_node_cb_cls); + GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); + barrier->nodes = NULL; + } + + while (NULL != (pos = barrier->cmds_head)) + { + GNUNET_CONTAINER_DLL_remove (barrier->cmds_head, + barrier->cmds_tail, + pos); + GNUNET_free (pos); + } + GNUNET_free (barrier); + return GNUNET_YES; +} + + +/** + * Deleting all barriers create in the context of this interpreter. + * + * @param is The interpreter. + */ +static void +interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is) +{ + GNUNET_CONTAINER_multishortmap_iterate (is->barriers, + free_barriers_cb, + is); + GNUNET_CONTAINER_multishortmap_destroy (is->barriers); +} + + /** * Finish the test run, return the final result. * @@ -285,6 +360,7 @@ finish_test (void *cls) GNUNET_free (is->commands); is->rc (is->rc_cls, is->result); + interpreter_delete_barriers (is); GNUNET_free (is->helper); GNUNET_free (is); } @@ -687,32 +763,6 @@ TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is, } -int -free_barrier_node_cb (void *cls, - const struct GNUNET_ShortHashCode *key, - void *value) -{ - struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls; - struct GNUNET_TESTING_NetjailNode *node = value; - struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier; - struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "free_barrier_node_cb\n"); - if (GNUNET_NO == is->finishing) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TST_interpreter_send_barrier_crossable\n"); - TST_interpreter_send_barrier_crossable (is, - barrier->name, - node->node_number); - } - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove ( - barrier->nodes, key, node)); - return GNUNET_YES; -} - - /** * Getting a barrier from the interpreter. * @@ -797,55 +847,6 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, } -int -free_barriers_cb (void *cls, - const struct GNUNET_ShortHashCode *key, - void *value) -{ - struct GNUNET_TESTING_Interpreter *is = cls; - struct GNUNET_TESTING_Barrier *barrier = value; - struct CommandListEntry *pos; - struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; - - if (NULL != barrier->nodes) - { - free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); - free_barrier_node_cb_cls->barrier = barrier; - free_barrier_node_cb_cls->is = is; - GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, - free_barrier_node_cb, - free_barrier_node_cb_cls); - GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); - barrier->nodes = NULL; - } - - while (NULL != (pos = barrier->cmds_head)) - { - GNUNET_CONTAINER_DLL_remove (barrier->cmds_head, - barrier->cmds_tail, - pos); - GNUNET_free (pos); - } - GNUNET_free (barrier); - return GNUNET_YES; -} - - -/** - * Deleting all barriers create in the context of this interpreter. - * - * @param is The interpreter. - */ -void -TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is) -{ - GNUNET_CONTAINER_multishortmap_iterate (is->barriers, - free_barriers_cb, - is); - GNUNET_CONTAINER_multishortmap_destroy (is->barriers); -} - - /** * Add a barrier to the loop. * |