From d8c29e0ad8da256d3fdc27921467e8df7a5693ad Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 21 May 2008 14:58:52 +0000 Subject: [PATCH] kill all free_string functions declared locally to cleanup dynars afterward, and use xbt_free_ref consitantly for that (plus plug two memleaks on the way in surf parser) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5485 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/gras/DataDesc/cbps.c | 4 ---- src/include/surf/surf.h | 1 - src/surf/network.c | 3 ++- src/surf/network_constant.c | 2 +- src/surf/network_gtnets.c | 2 +- src/surf/surfxml_parse.c | 12 ++++-------- src/surf/workstation_ptask_L07.c | 2 +- src/xbt/dynar.c | 15 +++++---------- 8 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/gras/DataDesc/cbps.c b/src/gras/DataDesc/cbps.c index c3f7e4ca06..df1b055db7 100644 --- a/src/gras/DataDesc/cbps.c +++ b/src/gras/DataDesc/cbps.c @@ -27,10 +27,6 @@ typedef struct s_gras_cbps { xbt_dynar_t globals; } s_gras_cbps_t; -static void free_string(void *d){ - free(*(void**)d); -} - gras_cbps_t gras_cbps_new(void) { gras_cbps_t res; diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 16dd1640d4..3210609378 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -575,7 +575,6 @@ XBT_PUBLIC(void) surf_exit(void); /* Prototypes of the functions that handle the properties */ XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */ void parse_properties(void); -void free_string(void*); /* Prototypes for functions handling routing and were factorized succesfully from the models */ void init_data(void); diff --git a/src/surf/network.c b/src/surf/network.c index c2ed3ea90d..7c81c2f8e2 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -162,7 +162,7 @@ static void parse_route_set_endpoints(void) src_id = network_card_new(A_surfxml_route_src); dst_id = network_card_new(A_surfxml_route_dst); route_action = A_surfxml_route_action; - route_link_list = xbt_dynar_new(sizeof(char *), &free_string); + route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } static void parse_route_set_route(void) @@ -217,6 +217,7 @@ static void add_route(void) src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16); dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16); + xbt_dynar_free(&keys); xbt_dynar_foreach (links, cpt, link) { TRY { diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 36664cc3a9..f961845876 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -59,7 +59,7 @@ static void parse_route_set_endpoints(void) src_id = network_card_new(A_surfxml_route_src); dst_id = network_card_new(A_surfxml_route_dst); route_action = A_surfxml_route_action; - route_link_list = xbt_dynar_new(sizeof(char *), &free_string); + route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } static void parse_route_set_route(void) diff --git a/src/surf/network_gtnets.c b/src/surf/network_gtnets.c index a37cdac2bb..66e8590898 100644 --- a/src/surf/network_gtnets.c +++ b/src/surf/network_gtnets.c @@ -223,7 +223,7 @@ static void parse_route_set_endpoints(void) /* nb_link = 0; link_name = NULL; */ - route_link_list = xbt_dynar_new(sizeof(char *), &free_string); + route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } /* KF*/ diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index e2170bac70..1b5c8fb45f 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -229,6 +229,7 @@ void ETag_surfxml_platform(void) surfxml_call_cb_functions(ETag_surfxml_platform_cb_list); + xbt_dynar_free(&route_link_list); xbt_dict_free(&random_data_list); xbt_dict_free(&set_list); @@ -480,11 +481,6 @@ void parse_properties(void) xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free); } -void free_string(void *d) -{ - free(*(void**)d); -} - void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function) { xbt_dynar_push(cb_list, &function); @@ -755,7 +751,7 @@ void parse_route_multi_set_endpoints(void) is_symmetric_route = A_surfxml_route_c_multi_symmetric; route_multi_size++; - route_link_list = xbt_dynar_new(sizeof(char *), &free_string); + route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } static int contains(xbt_dynar_t list, const char* value) @@ -890,14 +886,14 @@ static void convert_route_multi_to_routes(void) dst_names = (xbt_dynar_t)xbt_dict_get_or_null(set_list, dst); /* Add to dynar even if they are simple names */ if (src_names == NULL) { - src_names = xbt_dynar_new(sizeof(char *), &free_string); + src_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref); val = xbt_strdup(src); xbt_dynar_push(src_names, &val); if (strcmp(val,"$*") != 0 && NULL == xbt_dict_get_or_null(set, val)) THROW3(unknown_error,0,"(In route:multi (%s -> %s) source %s does not exist (not a set or a host)", src, dst, src); } if (dst_names == NULL) { - dst_names = xbt_dynar_new(sizeof(char *), &free_string); + dst_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref); val = xbt_strdup(dst); if (strcmp(val,"$*") != 0 && NULL == xbt_dict_get_or_null(set, val)) THROW3(unknown_error,0,"(In route:multi (%s -> %s) destination %s does not exist (not a set or a host)", src, dst, dst); diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index b66945fb43..ec0c05eda5 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -869,7 +869,7 @@ static void parse_route_set_endpoints(void) route_action = A_surfxml_route_action; - route_link_list = xbt_dynar_new(sizeof(char*), &free_string); + route_link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref); } static void parse_route_set_route(void) diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index f29b2806c8..ab89031e22 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -1005,11 +1005,6 @@ XBT_TEST_UNIT("double",test_dynar_double,"Dynars of doubles") { /* doxygen_string_cruft */ -/* The function we will use to free the data */ -static void free_string(void *d){ - free(*(void**)d); -} - /*******************************************************************************/ /*******************************************************************************/ /*******************************************************************************/ @@ -1021,7 +1016,7 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { char *s1,*s2; xbt_test_add0("==== Traverse the empty dynar"); - d=xbt_dynar_new(sizeof(char *),&free_string); + d=xbt_dynar_new(sizeof(char *),&xbt_free_ref); xbt_dynar_foreach(d,iter,s1){ xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar"); @@ -1031,7 +1026,7 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM); /* Populate_str [doxygen cruft] */ - d=xbt_dynar_new(sizeof(char*),&free_string); + d=xbt_dynar_new(sizeof(char*),&xbt_free_ref); /* 1. Populate the dynar */ for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); @@ -1066,7 +1061,7 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { xbt_test_add1("==== Unshift, traverse and pop %d strings",NB_ELEM); - d=xbt_dynar_new(sizeof(char**),&free_string); + d=xbt_dynar_new(sizeof(char**),&xbt_free_ref); for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); @@ -1094,7 +1089,7 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { xbt_test_add2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5); - d=xbt_dynar_new(sizeof(char*),&free_string); + d=xbt_dynar_new(sizeof(char*),&xbt_free_ref); for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); @@ -1135,7 +1130,7 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5)); - d=xbt_dynar_new(sizeof(char*),&free_string); + d=xbt_dynar_new(sizeof(char*),&xbt_free_ref); for (cpt=0; cpt< NB_ELEM; cpt++) { sprintf(buf,"%d",cpt); s1=strdup(buf); -- 2.20.1