From 5ceace97eb4b7bfabda26645817ab886850c6651 Mon Sep 17 00:00:00 2001 From: Euler Taveira Date: Thu, 30 Apr 2015 12:20:20 -0300 Subject: [PATCH] Fix some unchecked return values. Some event_add() return value were not checked. Either test the output or ignore it with (void). Adopt the former because it give us a chance to expose a bug. While in it, be consistent with the log messages. Spotted by Coverity. --- src/dnslookup.c | 11 ++++++++--- src/sbuf.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dnslookup.c b/src/dnslookup.c index 53ae344..ce3bbbe 100644 --- a/src/dnslookup.c +++ b/src/dnslookup.c @@ -554,6 +554,7 @@ static bool impl_init(struct DNSContext *ctx) int fd; struct dns_ctx *dctx; struct UdnsMeta *udns; + int err; dns_init(NULL, 0); @@ -574,7 +575,9 @@ static bool impl_init(struct DNSContext *ctx) return false; } event_set(&udns->ev_io, fd, EV_READ | EV_PERSIST, udns_io_cb, ctx); - event_add(&udns->ev_io, NULL); + err = event_add(&udns->ev_io, NULL); + if (err < 0) + log_warning("impl_init: event_add failed: %s", strerror(errno)); /* timer setup */ evtimer_set(&udns->ev_timer, udns_timer_cb, ctx); @@ -868,7 +871,8 @@ re_set: xfd->wait = new_wait; if (new_wait) { event_set(&xfd->ev, sock, new_wait | EV_PERSIST, xares_fd_cb, xfd); - event_add(&xfd->ev, NULL); + if (event_add(&xfd->ev, NULL) < 0) + log_warning("adns: event_add failed: %s", strerror(errno)); } else { xfd->in_use = 0; } @@ -933,7 +937,8 @@ static void impl_per_loop(struct DNSContext *ctx) tvp = ares_timeout(meta->chan, NULL, &tv); if (tvp != NULL) { - event_add(&meta->ev_timer, tvp); + if (event_add(&meta->ev_timer, tvp) < 0) + log_warning("impl_per_loop: event_add failed: %s", strerror(errno)); meta->timer_active = true; } diff --git a/src/sbuf.c b/src/sbuf.c index b9559d5..fad9a33 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -340,7 +340,7 @@ static bool sbuf_wait_for_data(SBuf *sbuf) event_set(&sbuf->ev, sbuf->sock, EV_READ | EV_PERSIST, sbuf_recv_cb, sbuf); err = event_add(&sbuf->ev, NULL); if (err < 0) { - log_warning("sbuf_wait_for_data: event_add: %s", strerror(errno)); + log_warning("sbuf_wait_for_data: event_add failed: %s", strerror(errno)); return false; } sbuf->wait_type = W_RECV; -- 2.39.5