From 86daf3fd20a70d10c1837afa9e35084f709869c6 Mon Sep 17 00:00:00 2001 From: schnorr Date: Wed, 21 Mar 2012 10:49:20 +0100 Subject: [PATCH 1/1] [trace] wipe out memory leaks in graphicator --- src/instr/instr_interface.c | 1 + src/instr/instr_routing.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index 00ac548987..fc03a78247 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -169,6 +169,7 @@ int TRACE_platform_graph_export_graphviz (const char *filename) xbt_graph_t g = instr_routing_platform_graph(); if (g == NULL) return 0; instr_routing_platform_graph_export_graphviz (g, filename); + xbt_graph_free_graph (g, xbt_free, xbt_free, NULL); return 1; } diff --git a/src/instr/instr_routing.c b/src/instr/instr_routing.c index b501bd7f91..12d6863c5a 100644 --- a/src/instr/instr_routing.c +++ b/src/instr/instr_routing.c @@ -430,21 +430,25 @@ static xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_d static xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges) { xbt_edge_t ret; - char *name; const char *sn = instr_node_name (s); const char *dn = instr_node_name (d); + int len = strlen(sn)+strlen(dn)+1; + char *name = (char*)malloc(len * sizeof(char)); - name = bprintf ("%s%s", sn, dn); - ret = xbt_dict_get_or_null (edges, name); - if (ret) return ret; - free (name); - name = bprintf ("%s%s", dn, sn); + + snprintf (name, len, "%s%s", sn, dn); ret = xbt_dict_get_or_null (edges, name); - if (ret) return ret; + if (ret == NULL){ + snprintf (name, len, "%s%s", dn, sn); + ret = xbt_dict_get_or_null (edges, name); + } - ret = xbt_graph_new_edge(graph, s, d, NULL); - xbt_dict_set (edges, name, ret, NULL); + if (ret == NULL){ + ret = xbt_graph_new_edge(graph, s, d, NULL); + xbt_dict_set (edges, name, ret, NULL); + } + free (name); return ret; } @@ -529,6 +533,8 @@ xbt_graph_t instr_routing_platform_graph (void) xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL); xbt_dict_t edges = xbt_dict_new_homogeneous(NULL); recursiveXBTGraphExtraction (ret, nodes, edges, global_routing->root, PJ_container_get_root()); + xbt_dict_free (&nodes); + xbt_dict_free (&edges); return ret; } -- 2.20.1