From 59ba73ddb4a68bea5e1a99f21a4d5d12587b6288 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 4 Apr 2015 14:56:03 +0200 Subject: [PATCH] dont segfault when exiting before everything is allocated (as on parse errors) --- src/surf/surf_routing_floyd.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/surf/surf_routing_floyd.cpp b/src/surf/surf_routing_floyd.cpp index 7d4e9423f8..e87df4f4e7 100644 --- a/src/surf/surf_routing_floyd.cpp +++ b/src/surf/surf_routing_floyd.cpp @@ -33,16 +33,19 @@ AsFloyd::~AsFloyd(){ int i, j; int table_size; table_size = (int)xbt_dynar_length(p_indexNetworkElm); - /* Delete link_table */ - for (i = 0; i < table_size; i++) - for (j = 0; j < table_size; j++) - generic_free_route(TO_FLOYD_LINK(i, j)); - xbt_free(p_linkTable); - /* Delete bypass dict */ - xbt_dict_free(&p_bypassRoutes); - /* Delete predecessor and cost table */ - xbt_free(p_predecessorTable); - xbt_free(p_costTable); + if (p_linkTable == NULL) // Dealing with a parse error in the file? + return; + /* Delete link_table */ + for (i = 0; i < table_size; i++) + for (j = 0; j < table_size; j++) { + generic_free_route(TO_FLOYD_LINK(i, j)); + } + xbt_free(p_linkTable); + /* Delete bypass dict */ + xbt_dict_free(&p_bypassRoutes); + /* Delete predecessor and cost table */ + xbt_free(p_predecessorTable); + xbt_free(p_costTable); } /* Business methods */ -- 2.20.1