Call sockaddrfree(&e->local_address) in free_edge() instead of exit_edges().
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 4 Jul 2015 15:53:11 +0000 (17:53 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 4 Jul 2015 15:53:11 +0000 (17:53 +0200)
The proper place to clean up resources of objects is in their
destructor. This makes sure proper cleanup when edge_del() is called as
well. At exit, free_edge() is called on all edges by free_edge_tree(),
which is called by exit_nodes().

src/edge.c

index 6539630..0e35cd1 100644 (file)
@@ -64,12 +64,6 @@ void free_edge_tree(splay_tree_t *edge_tree) {
 }
 
 void exit_edges(void) {
-       // since edge_weight_tree does not have delete action defined
-       // we have to cleanup it on exit
-       for splay_each(edge_t, e, edge_weight_tree) {
-                       sockaddrfree(&e->address);
-                       sockaddrfree(&e->local_address);
-               }
        splay_delete_tree(edge_weight_tree);
 }
 
@@ -81,6 +75,7 @@ edge_t *new_edge(void) {
 
 void free_edge(edge_t *e) {
        sockaddrfree(&e->address);
+       sockaddrfree(&e->local_address);
 
        free(e);
 }