]> git.meshlink.io Git - catta/commitdiff
check for failure of catta_set_nonblock in simple-watch and iface-windows
authorSven M. Hallberg <pesco@khjk.org>
Thu, 16 Oct 2014 15:36:14 +0000 (17:36 +0200)
committerSven M. Hallberg <pesco@khjk.org>
Thu, 16 Oct 2014 15:36:14 +0000 (17:36 +0200)
src/iface-windows.c
src/simple-watch.c

index 9a57f7c2b7f8eda2268e7b740abb0fff17e3e841..1d8d0f3d9671c995f7b5316b057cd92b60484819 100644 (file)
@@ -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)
index 2992d87108075144468a4110f469b90770515129..a7b4e4218024aed1c1194d5c231e0b12230a86cb 100644 (file)
@@ -33,6 +33,7 @@
 #include <catta/malloc.h>
 #include <catta/timeval.h>
 #include <catta/simple-watch.h>
+#include <catta/log.h>
 #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) {