From: Guus Sliepen Date: Sun, 27 Jun 2021 14:01:52 +0000 (+0200) Subject: Log errors when add_edge() fails to insert into the edge trees. X-Git-Tag: release-1.1pre18~8 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=bda16410075a63b147179c15aa75640decf17ec7;p=tinc Log errors when add_edge() fails to insert into the edge trees. 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. --- diff --git a/src/edge.c b/src/edge.c index 5491d8ac..ad6ec02b 100644 --- a/src/edge.c +++ b/src/edge.c @@ -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) {