From d05227640d4f8e5be751a522226c0e7243388d16 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 15 Feb 2016 22:36:58 +0100 Subject: [PATCH] plug some memleaks in simdag tests --- include/simgrid/host.h | 2 +- include/simgrid/simdag.h | 3 +-- src/simdag/sd_workstation.cpp | 2 +- src/simgrid/host.cpp | 2 +- teshsuite/simdag/platforms/basic_parsing_test.c | 10 ++++++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 410091f56f..b73a25da42 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -21,7 +21,7 @@ SG_BEGIN_DECL() XBT_PUBLIC(size_t) sg_host_count(); -XBT_PUBLIC(const sg_host_t *) sg_host_list(void); +XBT_PUBLIC(sg_host_t *) sg_host_list(void); XBT_PUBLIC(size_t) sg_host_extension_create(void(*deleter)(void*)); XBT_PUBLIC(void*) sg_host_extension_get(sg_host_t host, size_t rank); diff --git a/include/simgrid/simdag.h b/include/simgrid/simdag.h index 0978733cda..c627e0d2b6 100644 --- a/include/simgrid/simdag.h +++ b/include/simgrid/simdag.h @@ -89,8 +89,7 @@ typedef xbt_dictelm_t SD_storage_t; * @see sg_host_t * @{ */ -XBT_PUBLIC(const SD_link_t *) SD_route_get_list(sg_host_t src, - sg_host_t dst); +XBT_PUBLIC(SD_link_t *) SD_route_get_list(sg_host_t src, sg_host_t dst); XBT_PUBLIC(int) SD_route_get_size(sg_host_t src, sg_host_t dst); XBT_PUBLIC(double) SD_route_get_latency(sg_host_t src, sg_host_t dst); diff --git a/src/simdag/sd_workstation.cpp b/src/simdag/sd_workstation.cpp index 8f9cef43b7..5e8ed9779a 100644 --- a/src/simdag/sd_workstation.cpp +++ b/src/simdag/sd_workstation.cpp @@ -23,7 +23,7 @@ * \return an array of the \ref SD_link_t composing the route * \see SD_route_get_size(), SD_link_t */ -const SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst) +SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst) { xbt_dynar_t surf_route; SD_link_t* list; diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 08c5d4fc6d..9e26ad8f8e 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -29,7 +29,7 @@ size_t sg_host_count() * internally). * \see sg_host_count() */ -const sg_host_t *sg_host_list(void) { +sg_host_t *sg_host_list(void) { xbt_assert(sg_host_count() > 0, "There is no host!"); return (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar()); } diff --git a/teshsuite/simdag/platforms/basic_parsing_test.c b/teshsuite/simdag/platforms/basic_parsing_test.c index e7cbf0ba80..cd9e9957a6 100644 --- a/teshsuite/simdag/platforms/basic_parsing_test.c +++ b/teshsuite/simdag/platforms/basic_parsing_test.c @@ -13,8 +13,8 @@ int main(int argc, char **argv) /* SD initialization */ sg_host_t w1, w2; - const sg_host_t *workstations; - const SD_link_t *route; + sg_host_t *workstations; + SD_link_t *route; const char *name1; const char *name2; int route_size, i, j, k; @@ -34,9 +34,9 @@ int main(int argc, char **argv) printf("Workstation number: %zu, link number: %d\n", sg_host_count(), sg_link_count()); + workstations = sg_host_list(); if (argc >= 3) { if (!strcmp(argv[2], "ONE_LINK")) { - workstations = sg_host_list(); w1 = workstations[0]; w2 = workstations[1]; name1 = sg_host_get_name(w1); @@ -55,9 +55,9 @@ int main(int argc, char **argv) printf("Route latency = %f, route bandwidth = %f\n", SD_route_get_latency(w1, w2), SD_route_get_bandwidth(w1, w2)); + xbt_free(route); } if (!strcmp(argv[2], "FULL_LINK")) { - workstations = sg_host_list(); list_size = sg_host_count(); for (i = 0; i < list_size; i++) { w1 = workstations[i]; @@ -78,6 +78,7 @@ int main(int argc, char **argv) printf(" Route latency = %f, route bandwidth = %f\n", SD_route_get_latency(w1, w2), SD_route_get_bandwidth(w1, w2)); + xbt_free(route); } } } @@ -87,6 +88,7 @@ int main(int argc, char **argv) "SG_TEST_mem")); } } + xbt_free(workstations); SD_exit(); return 0; -- 2.20.1