From 662f364d099426b64f63e36d97161adde3fe7fcb Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 4 Jun 2016 21:03:36 +0200 Subject: [PATCH] Check return value from uev_io_init() at runtime Possible resource leak due to unchecked return value from uev_io_init() found by Coverity Scan. Signed-off-by: Joachim Nilsson --- api.c | 3 ++- inetd.c | 8 +++++++- plugin.c | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api.c b/api.c index 1a628884..e1f1dd63 100644 --- a/api.c +++ b/api.c @@ -364,7 +364,8 @@ int api_init(uev_ctx_t *ctx) if (-1 == listen(sd, 10)) goto error; - return uev_io_init(ctx, &api_watcher, cb, NULL, sd, UEV_READ); + if (!uev_io_init(ctx, &api_watcher, cb, NULL, sd, UEV_READ)) + return 0; error: _pe("Failed intializing API socket"); diff --git a/inetd.c b/inetd.c index 154a44bb..c5681770 100755 --- a/inetd.c +++ b/inetd.c @@ -239,7 +239,13 @@ static int spawn_socket(inetd_t *inetd) } } - uev_io_init(ctx, &inetd->watcher, socket_cb, inetd->svc, sd, UEV_READ); + if (uev_io_init(ctx, &inetd->watcher, socket_cb, inetd->svc, sd, UEV_READ)) { + FLOG_PERROR("Failed setting up inetd watcher for %s", inetd->name); + close(sd); + return -errno; + } + + return 0; } diff --git a/plugin.c b/plugin.c index 031e0d03..11a37f1e 100644 --- a/plugin.c +++ b/plugin.c @@ -211,7 +211,8 @@ static void init_plugins(uev_ctx_t *ctx) PLUGIN_ITERATOR(p, tmp) { if (is_io_plugin(p)) { _d("Initializing plugin %s for I/O", basename(p->name)); - uev_io_init(ctx, &p->watcher, generic_io_cb, p, p->io.fd, p->io.flags); + if (uev_io_init(ctx, &p->watcher, generic_io_cb, p, p->io.fd, p->io.flags)) + _e("Failed setting up I/O plugin %s", basename(p->name)); } } }