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 60335fd08df50955cc243f54217de043a6143d05..34e042ad59fbd217bf6962d93563c491a1918f26 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 a6874332091f1685ba14f863b19ca0d286ecfc77..39dc03c7229d79d7d321781ba78283fd1ea4f59e 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;
 }