From dc26ecc28046d9f3cb56f10b22636d04218ad545 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 6 May 2014 22:34:06 +0200 Subject: [PATCH 1/1] Fix a few more issues found by Coverity. --- src/net_setup.c | 6 ++++++ src/xmalloc.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/net_setup.c b/src/net_setup.c index 60335fd..34e042a 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -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); diff --git a/src/xmalloc.c b/src/xmalloc.c index a687433..39dc03c 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -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; } -- 2.25.1