From aa30c333011fc09b057c0468151b73ba6828b25e Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Thu, 16 Oct 2014 17:36:14 +0200 Subject: [PATCH] check for failure of catta_set_nonblock in simple-watch and iface-windows --- src/iface-windows.c | 15 ++++++++++++--- src/simple-watch.c | 19 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/iface-windows.c b/src/iface-windows.c index 9a57f7c..1d8d0f3 100644 --- a/src/iface-windows.c +++ b/src/iface-windows.c @@ -471,8 +471,12 @@ int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) catta_log_error("pipe() in catta_interface_monitor_init_osdep failed"); return -1; } - catta_set_nonblock(m->osdep.pipefd[0]); - catta_set_nonblock(m->osdep.pipefd[1]); + if(catta_set_nonblock(m->osdep.pipefd[0]) < 0 || + catta_set_nonblock(m->osdep.pipefd[1]) < 0) + { + catta_log_error(__FILE__": catta_set_nonblock failed: %s", errnostrsocket()); + goto fail; + } m->osdep.icnhandle = NULL; m->osdep.acnhandle = NULL; @@ -485,7 +489,7 @@ int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) m); if(!m->osdep.watch) { catta_log_error(__FILE__": Failed to create watch."); - return -1; + goto fail; } // request async notification on interface changes @@ -505,6 +509,11 @@ int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) catta_log_error("NotifyUnicastIpAddressChange failed: %u", (unsigned int)r); return 0; + +fail: + closesocket(m->osdep.pipefd[0]); + closesocket(m->osdep.pipefd[1]); + return -1; } void catta_interface_monitor_free_osdep(CattaInterfaceMonitor *m) diff --git a/src/simple-watch.c b/src/simple-watch.c index 2992d87..a7b4e42 100644 --- a/src/simple-watch.c +++ b/src/simple-watch.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "fdutil.h" // catta_set_nonblock #include "internal.h" // closesocket @@ -317,13 +318,16 @@ CattaSimplePoll *catta_simple_poll_new(void) { winsock_init(); // on Windows, pipe uses sockets; no-op on other platforms if (pipe(s->wakeup_pipe) < 0) { - catta_free(s); - winsock_exit(); - return NULL; + catta_log_error(__FILE__": pipe() failed: %s", errnostrsocket()); + goto fail; } - catta_set_nonblock(s->wakeup_pipe[0]); - catta_set_nonblock(s->wakeup_pipe[1]); + if (catta_set_nonblock(s->wakeup_pipe[0]) < 0 || + catta_set_nonblock(s->wakeup_pipe[1]) < 0) + { + catta_log_error(__FILE__": O_NONBLOCK failed: %s", errnostrsocket()); + goto fail; + } s->api.userdata = s; @@ -358,6 +362,11 @@ CattaSimplePoll *catta_simple_poll_new(void) { CATTA_LLIST_HEAD_INIT(CattaTimeout, s->timeouts); return s; + +fail: + catta_free(s); + winsock_exit(); + return NULL; } void catta_simple_poll_free(CattaSimplePoll *s) { -- 2.39.5