gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit a44a6b8c82c938660b617464c2336a49270d523e
parent ec694204b034b8add38dace561196319e46eba9b
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 19 May 2024 21:23:37 +0200

-fix leaks

Diffstat:
Msrc/lib/testing/test_testing_api.c | 8++++++++
Msrc/lib/testing/testing_api_cmd_get_topo.c | 24++++++++++++++++++++----
2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/lib/testing/test_testing_api.c b/src/lib/testing/test_testing_api.c @@ -51,6 +51,12 @@ main (int argc, NULL), GNUNET_TESTING_cmd_end () }; + struct GNUNET_TESTING_Command netjail[] = { + GNUNET_TESTING_cmd_load_topology_from_string ( + "load-topology", + ""), + GNUNET_TESTING_cmd_end () + }; struct GNUNET_TESTING_Command commands[] = { GNUNET_TESTING_cmd_batch ("batch", batch), @@ -108,6 +114,8 @@ main (int argc, GNUNET_TESTING_cmd_rewind_ip ("rewind", "wait-sleep", 4), + GNUNET_TESTING_cmd_batch ("netjail", + netjail), GNUNET_TESTING_cmd_end () }; diff --git a/src/lib/testing/testing_api_cmd_get_topo.c b/src/lib/testing/testing_api_cmd_get_topo.c @@ -50,6 +50,10 @@ struct TopologyState */ const char *topology_string; + /** + * Same as @e topology_string, but set if we need + * to release the memory. + */ char *topology_alloc; /** @@ -67,6 +71,11 @@ cleanup (void *cls) { struct TopologyState *ts = cls; + if (NULL != ts->topology) + { + GNUNET_TESTING_free_topology (ts->topology); + ts->topology = NULL; + } GNUNET_free (ts->topology_alloc); GNUNET_free (ts); } @@ -107,7 +116,7 @@ get_topo_string_from_file (const char *topology_data_file) LOG (GNUNET_ERROR_TYPE_ERROR, "Topology file %s not found\n", topology_data_file); - GNUNET_assert (0); + return NULL; } if (GNUNET_OK != GNUNET_DISK_file_size (topology_data_file, @@ -118,7 +127,7 @@ get_topo_string_from_file (const char *topology_data_file) LOG (GNUNET_ERROR_TYPE_ERROR, "Could not determine size of topology file %s\n", topology_data_file); - GNUNET_assert (0); + return NULL; } data = GNUNET_malloc_large (fs + 1); GNUNET_assert (NULL != data); @@ -151,10 +160,16 @@ run (void *cls, if (NULL == ts->topology_string) { - ts->topology_alloc = get_topo_string_from_file (ts->file_name); + ts->topology_alloc + = get_topo_string_from_file (ts->file_name); + if (NULL == ts->topology_alloc) + GNUNET_TESTING_FAIL (is); ts->topology_string = ts->topology_alloc; } - ts->topology = GNUNET_TESTING_get_topo_from_string_ (ts->topology_string); + ts->topology + = GNUNET_TESTING_get_topo_from_string_ (ts->topology_string); + if (NULL == ts->topology) + GNUNET_TESTING_FAIL (is); } @@ -185,6 +200,7 @@ GNUNET_TESTING_cmd_load_topology_from_string ( { struct TopologyState *ts; + GNUNET_assert (NULL != topology_string); ts = GNUNET_new (struct TopologyState); ts->label = label; ts->topology_string = topology_string;