From 87df203c4b021746b5a4ff626243f71af7874e6c Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Thu, 31 May 2012 10:40:36 +0000 Subject: [PATCH] -fixed memory leaks and added windows support for temp dirs --- src/testing/test_testing_new_peerstartup.c | 29 +++++++++++++++++++--- src/testing/testing_new.c | 3 ++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/testing/test_testing_new_peerstartup.c b/src/testing/test_testing_new_peerstartup.c index 18d8217a1..3793e8436 100644 --- a/src/testing/test_testing_new_peerstartup.c +++ b/src/testing/test_testing_new_peerstartup.c @@ -50,6 +50,11 @@ struct TestingContext * The peer which has been started by the testing system */ struct GNUNET_TESTING_Peer *peer; + + /** + * The running configuration of the peer + */ + struct GNUNET_CONFIGURATION_Handle *cfg; }; @@ -66,6 +71,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (GNUNET_OK == GNUNET_TESTING_peer_stop (test_ctx->peer)); GNUNET_TESTING_peer_destroy (test_ctx->peer); + GNUNET_CONFIGURATION_destroy (test_ctx->cfg); GNUNET_TESTING_hostkeys_unload (test_ctx->system); GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); GNUNET_free (test_ctx); @@ -86,14 +92,28 @@ run (void *cls, char *const *args, const char *cfgfile, char *data_dir; char *hostkeys_file; char *emsg; + char *tmpdir_; char *tmpdir; +#ifdef MINGW + char *tmpdir_w; +#endif + struct GNUNET_PeerIdentity id; - GNUNET_asprintf (&tmpdir, "%s/%s", P_tmpdir, - "test-gnunet-testing_new-XXXXXX"); + tmpdir_ = getenv ("TMPDIR"); + tmpdir_ = tmpdir_ ? tmpdir_ : "/tmp"; + GNUNET_asprintf (&tmpdir, "%s/%s", tmpdir_, "test-gnunet-testing_new-XXXXXX"); +#ifdef MINGW + tmpdir_w = GNUNET_malloc (MAX_PATH + 1); + GNUNET_assert (ERROR_SUCCESS == plibc_conv_to_win_path (tmpdir, tmpdir_w)); + GNUNET_free (tmpdir); + tmpdir = tmpdir_w; + GNUNET_assert (0 == _mktemp_s (tmpdir, strlen (tmpdir) + 1)); +#else GNUNET_assert (mkdtemp (tmpdir) == tmpdir); - /* LOG (GNUNET_ERROR_TYPE_ERROR, */ - /* "Temporary directory: %s\n", tmpdir); */ +#endif + LOG (GNUNET_ERROR_TYPE_ERROR, + "Temporary directory: %s\n", tmpdir); system = GNUNET_TESTING_system_create (tmpdir, "localhost"); GNUNET_assert (NULL != system); @@ -113,6 +133,7 @@ run (void *cls, char *const *args, const char *cfgfile, test_ctx = GNUNET_malloc (sizeof (struct TestingContext)); test_ctx->system = system; test_ctx->peer = peer; + test_ctx->cfg = new_cfg; GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC (5), &do_shutdown, test_ctx); diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c index 1bdf7a45f..c19f5c8e1 100644 --- a/src/testing/testing_new.c +++ b/src/testing/testing_new.c @@ -592,13 +592,14 @@ update_config_sections (void *cls, GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "ACCEPT_FROM", &orig_allowed_hosts)) { - orig_allowed_hosts = "127.0.0.1;"; + orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); } if (NULL == uc->system->controller) allowed_hosts = GNUNET_strdup (orig_allowed_hosts); else GNUNET_asprintf (&allowed_hosts, "%s %s;", orig_allowed_hosts, uc->system->controller); + GNUNET_free (orig_allowed_hosts); GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, "ACCEPT_FROM", allowed_hosts); GNUNET_free (allowed_hosts); -- 2.25.1