Close the socket upon erroneous exit as well.
[doldaconnect.git] / daemon / net.c
index 0f7be54..3cd12dc 100644 (file)
@@ -33,7 +33,6 @@
 #include <netinet/in.h>
 #include <netdb.h>
 #include <sys/signal.h>
-#include <printf.h>
 #ifdef HAVE_LINUX_SOCKIOS_H
 #include <linux/sockios.h>
 #endif
@@ -129,6 +128,7 @@ int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf)
                } else {
                    free(ipv4);
                    free(conf.ifc_buf);
+                   close(sock);
                    flog(LOG_WARNING, "could not locate an unambiguous interface for determining your public IP address - set net.publicif");
                    errno = ENFILE; /* XXX: There's no appropriate one for this... */
                    return(-1);
@@ -593,12 +593,6 @@ struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, v
        errno = EOPNOTSUPP;
        return(NULL);
     }
-    /* I don't know if this is actually correct (it probably isn't),
-     * but since, at on least Linux systems, PF_* are specifically
-     * #define'd to their AF_* counterparts, it allows for a severely
-     * smoother implementation. If it breaks something on your
-     * platform, please tell me so.
-     */
     if(confgetint("net", "mode") == 0)
        return(netcslistenlocal(type, name, namelen, func, data));
     errno = EOPNOTSUPP;