From d3e5900f733e299b7a2b57c16d09f92c200b743e Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 1 Sep 2018 18:55:22 +0200 Subject: [PATCH] Refactor, use LIST_FOREACH_SAFE() instead of while() in uev_exit() Signed-off-by: Joachim Nilsson --- src/uev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/uev.c b/src/uev.c index 8188c41..d168775 100644 --- a/src/uev.c +++ b/src/uev.c @@ -203,14 +203,14 @@ int uev_init(uev_ctx_t *ctx) */ int uev_exit(uev_ctx_t *ctx) { + uev_t *w, *next; + if (!ctx) { errno = EINVAL; return -1; } - while (!LIST_EMPTY(&ctx->watchers)) { - uev_t *w = LIST_FIRST(&ctx->watchers); - + LIST_FOREACH_SAFE(w, &ctx->watchers, link, next) { /* Remove from internal list */ LIST_REMOVE(w, link); @@ -233,6 +233,7 @@ int uev_exit(uev_ctx_t *ctx) } } + LIST_INIT(&ctx->watchers); ctx->running = 0; close(ctx->fd); ctx->fd = -1;