Fix a few more issues found by Coverity.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 6 May 2014 20:34:06 +0000 (22:34 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 6 May 2014 20:34:06 +0000 (22:34 +0200)
src/net_setup.c
src/xmalloc.c

index 60335fd..34e042a 100644 (file)
@@ -404,6 +404,7 @@ static bool setup_myself(void) {
                        proxytype = PROXY_EXEC;
                } else {
                        logger(LOG_ERR, "Unknown proxy type %s!", proxy);
+                       free(proxy);
                        return false;
                }
 
@@ -415,6 +416,7 @@ static bool setup_myself(void) {
                        case PROXY_EXEC:
                                if(!space || !*space) {
                                        logger(LOG_ERR, "Argument expected for proxy type exec!");
+                                       free(proxy);
                                        return false;
                                }
                                proxyhost =  xstrdup(space);
@@ -433,6 +435,7 @@ static bool setup_myself(void) {
                                        *space++ = 0, proxypass = space;
                                if(!proxyhost || !*proxyhost || !proxyport || !*proxyport) {
                                        logger(LOG_ERR, "Host and port argument expected for proxy!");
+                                       free(proxy);
                                        return false;
                                }
                                proxyhost = xstrdup(proxyhost);
@@ -486,6 +489,7 @@ static bool setup_myself(void) {
                        routing_mode = RMODE_HUB;
                else {
                        logger(LOG_ERR, "Invalid routing mode!");
+                       free(mode);
                        return false;
                }
                free(mode);
@@ -500,6 +504,7 @@ static bool setup_myself(void) {
                        forwarding_mode = FMODE_KERNEL;
                else {
                        logger(LOG_ERR, "Invalid forwarding mode!");
+                       free(mode);
                        return false;
                }
                free(mode);
@@ -526,6 +531,7 @@ static bool setup_myself(void) {
                        broadcast_mode = BMODE_DIRECT;
                else {
                        logger(LOG_ERR, "Invalid broadcast mode!");
+                       free(mode);
                        return false;
                }
                free(mode);
index a687433..39dc03c 100644 (file)
@@ -113,9 +113,12 @@ char *xstrdup(const char *s)
 {
   char *p;
   
+  if(!s)
+    return NULL;
+
   p = strdup(s);
   if(!p)
-    xalloc_fail (s ? (int)strlen(s) : 0);
+    xalloc_fail ((int)strlen(s));
   return p;
 }