]> git.meshlink.io Git - meshlink/commitdiff
Fix a crash when meshlink_open() is called with an invalid confbase.
authorGuus Sliepen <guus@sliepen.org>
Wed, 30 Jul 2014 14:59:38 +0000 (16:59 +0200)
committerGuus Sliepen <guus@sliepen.org>
Wed, 30 Jul 2014 14:59:38 +0000 (16:59 +0200)
src/conf.c
src/connection.c
src/edge.c
src/net_setup.c
src/node.c
src/protocol.c

index 36c10acb45d3d025458de83fdc89bd52f8824d43..5231a9dfca25fc16c1a8fd3fbf63b9c0a8001081 100644 (file)
@@ -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;
 }
 
index 05a9d653dc3bf377128b5eb73bd4017dfba2c2c5..cbe7a9d610277e0f9c1ef57910ced33f7b9a956c 100644 (file)
@@ -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) {
index 455b2301e95333fc78d5ec68adfd8cf1c4c055fb..efb90dfeaaffd49b3f9262b8354384bafb1cd21a 100644 (file)
@@ -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 */
index 8b0fd8fde443ced49bb80905bf7df3459ded601c..ce9a59ad230b0723e5bafeed12f312fed629b4a5 100644 (file)
@@ -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)
index 7fc476f480aab645076dda3f856d3c0a2585fabb..b7b39927948b2e8579b71a1f07a2aa9261266f99 100644 (file)
@@ -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));
 }
 
index 4cf351551820d4753206cbcb94ae5b7a9c8ca719..4b7d6016e44128f06dfd43dd7633374a7cb22a63 100644 (file)
@@ -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);
 }