From: Guus Sliepen Date: Tue, 9 Oct 2012 11:23:12 +0000 (+0200) Subject: Fix deleting connections from the connection list. X-Git-Tag: release-1.1pre3~18 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=f62b4a91344bd0de09e7fb4e4c8c1993ffc027c3;p=tinc Fix deleting connections from the connection list. --- diff --git a/src/connection.c b/src/connection.c index cbe704b5..598b5e59 100644 --- a/src/connection.c +++ b/src/connection.c @@ -91,12 +91,7 @@ void connection_add(connection_t *c) { } void connection_del(connection_t *c) { - for list_each(connection_t, c, connection_list) { - if(node->data == c) { - list_delete_node(connection_list, node); - return; - } - } + list_delete(connection_list, c); } bool dump_connections(connection_t *cdump) { diff --git a/src/list.c b/src/list.c index 8d0c9c89..18765d49 100644 --- a/src/list.c +++ b/src/list.c @@ -150,6 +150,12 @@ void list_delete_tail(list_t *list) { list_delete_node(list, list->tail); } +void list_delete(list_t *list, const void *data) { + for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) + if(node->data == data) + list_delete_node(list, node); +} + /* Head/tail lookup */ void *list_get_head(list_t *list) { @@ -169,7 +175,7 @@ void *list_get_tail(list_t *list) { /* Fast list deletion */ void list_delete_list(list_t *list) { - for(list_node_t *node = list->head, *next; next = node->next, node; node = next) + for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) list_free_node(list, node); list_free(list); @@ -178,12 +184,12 @@ void list_delete_list(list_t *list) { /* Traversing */ void list_foreach_node(list_t *list, list_action_node_t action) { - for(list_node_t *node = list->head, *next; next = node->next, node; node = next) + for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) action(node); } void list_foreach(list_t *list, list_action_t action) { - for(list_node_t *node = list->head, *next; next = node->next, node; node = next) + for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) if(node->data) action(node->data); } diff --git a/src/list.h b/src/list.h index 855b4272..4a863167 100644 --- a/src/list.h +++ b/src/list.h @@ -57,6 +57,8 @@ extern list_node_t *list_insert_tail(list_t *, void *); extern list_node_t *list_insert_after(list_t *, list_node_t *, void *); extern list_node_t *list_insert_before(list_t *, list_node_t *, void *); +extern void list_delete(list_t *, const void *); + extern void list_unlink_node(list_t *, list_node_t *); extern void list_delete_node(list_t *, list_node_t *);