From a0098cfdb9047a31dd1e5e73f34d429ac366c424 Mon Sep 17 00:00:00 2001 From: Kery Wu Date: Fri, 1 Jan 2016 10:32:57 +0800 Subject: [PATCH] Fix the crash issue in free_connections --- src/local.c | 6 ++---- src/server.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/local.c b/src/local.c index 7a89a66b..d3d528a3 100644 --- a/src/local.c +++ b/src/local.c @@ -198,10 +198,8 @@ int create_and_bind(const char *addr, const char *port) static void free_connections(struct ev_loop *loop) { - struct cork_dllist_item *curr; - for (curr = cork_dllist_start(&connections); - !cork_dllist_is_end(&connections, curr); - curr = curr->next) { + struct cork_dllist_item *curr, *next; + cork_dllist_foreach_void (&connections, curr, next) { server_t *server = cork_container_of(curr, server_t, entries); remote_t *remote = server->remote; close_and_free_server(loop, server); diff --git a/src/server.c b/src/server.c index 0a51c09c..3bc82114 100644 --- a/src/server.c +++ b/src/server.c @@ -205,10 +205,8 @@ static void stat_update_cb(EV_P_ ev_timer *watcher, int revents) static void free_connections(struct ev_loop *loop) { - struct cork_dllist_item *curr; - for (curr = cork_dllist_start(&connections); - !cork_dllist_is_end(&connections, curr); - curr = curr->next) { + struct cork_dllist_item *curr, *next; + cork_dllist_foreach_void (&connections, curr, next) { server_t *server = cork_container_of(curr, server_t, entries); remote_t *remote = server->remote; close_and_free_server(loop, server);