From f2b21858a8e77663a02c2d586b21c5568fb435a0 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 30 Jul 2014 16:59:38 +0200 Subject: [PATCH] Fix a crash when meshlink_open() is called with an invalid confbase. --- src/conf.c | 3 ++- src/connection.c | 7 ++++++- src/edge.c | 4 +++- src/net_setup.c | 12 +++++++----- src/node.c | 8 ++++++-- src/protocol.c | 4 +++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/conf.c b/src/conf.c index 36c10acb..5231a9df 100644 --- a/src/conf.c +++ b/src/conf.c @@ -51,7 +51,8 @@ void init_configuration(splay_tree_t **config_tree) { } void exit_configuration(splay_tree_t **config_tree) { - splay_delete_tree(*config_tree); + if(*config_tree) + splay_delete_tree(*config_tree); *config_tree = NULL; } diff --git a/src/connection.c b/src/connection.c index 05a9d653..cbe7a9d6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -36,8 +36,13 @@ void init_connections(meshlink_handle_t *mesh) { } void exit_connections(meshlink_handle_t *mesh) { - list_delete_list(mesh->connections); + if(mesh->connections) + list_delete_list(mesh->connections); + free_connection(mesh->everyone); + + mesh->connections = NULL; + mesh->everyone = NULL; } connection_t *new_connection(void) { diff --git a/src/edge.c b/src/edge.c index 455b2301..efb90dfe 100644 --- a/src/edge.c +++ b/src/edge.c @@ -61,7 +61,9 @@ void free_edge_tree(splay_tree_t *edge_tree) { } void exit_edges(meshlink_handle_t *mesh) { - splay_delete_tree(mesh->edges); + if(mesh->edges) + splay_delete_tree(mesh->edges); + mesh->edges = NULL; } /* Creation and deletion of connection elements */ diff --git a/src/net_setup.c b/src/net_setup.c index 8b0fd8fd..ce9a59ad 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -377,11 +377,13 @@ bool setup_network(meshlink_handle_t *mesh) { close all open network connections */ void close_network_connections(meshlink_handle_t *mesh) { - for(list_node_t *node = mesh->connections->head, *next; node; node = next) { - next = node->next; - connection_t *c = node->data; - c->outgoing = NULL; - terminate_connection(mesh, c, false); + if(mesh->connections) { + for(list_node_t *node = mesh->connections->head, *next; node; node = next) { + next = node->next; + connection_t *c = node->data; + c->outgoing = NULL; + terminate_connection(mesh, c, false); + } } if(mesh->outgoings) diff --git a/src/node.c b/src/node.c index 7fc476f4..b7b39927 100644 --- a/src/node.c +++ b/src/node.c @@ -42,8 +42,12 @@ void init_nodes(meshlink_handle_t *mesh) { void exit_nodes(meshlink_handle_t *mesh) { pthread_mutex_lock(&(mesh->nodes_mutex)); - hash_free(mesh->node_udp_cache); - splay_delete_tree(mesh->nodes); + if(mesh->node_udp_cache) + hash_free(mesh->node_udp_cache); + if(mesh->nodes) + splay_delete_tree(mesh->nodes); + mesh->node_udp_cache = NULL; + mesh->nodes = NULL; pthread_mutex_unlock(&(mesh->nodes_mutex)); } diff --git a/src/protocol.c b/src/protocol.c index 4cf35155..4b7d6016 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -200,7 +200,9 @@ void init_requests(meshlink_handle_t *mesh) { } void exit_requests(meshlink_handle_t *mesh) { - splay_delete_tree(mesh->past_request_tree); + if(mesh->past_request_tree) + splay_delete_tree(mesh->past_request_tree); + mesh->past_request_tree = NULL; timeout_del(&mesh->loop, &mesh->past_request_timeout); } -- 2.39.2