Log errors when add_edge() fails to insert into the edge trees.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 27 Jun 2021 14:01:52 +0000 (16:01 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 27 Jun 2021 14:09:41 +0000 (16:09 +0200)
This should never happen, but if it does we want to have it at least
logged instead of causing issues later on.

Based on a patch from arsh0r.

src/edge.c

index 5491d8a..ad6ec02 100644 (file)
@@ -83,14 +83,26 @@ void free_edge(edge_t *e) {
 }
 
 void edge_add(edge_t *e) {
-       splay_insert(edge_weight_tree, e);
-       splay_insert(e->from->edge_tree, e);
+       splay_node_t *node = splay_insert(e->from->edge_tree, e);
+
+       if(!node) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Edge from %s to %s already exists in edge_tree\n", e->from->name, e->to->name);
+               return;
+       }
+
 
        e->reverse = lookup_edge(e->to, e->from);
 
        if(e->reverse) {
                e->reverse->reverse = e;
        }
+
+       node = splay_insert(edge_weight_tree, e);
+
+       if(!node) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Edge from %s to %s already exists in edge_weight_tree\n", e->from->name, e->to->name);
+               return;
+       }
 }
 
 void edge_del(edge_t *e) {