[lxc-devel] [PATCH 4/4] coverity: fix leak when ipv6 gw is auto

Dwight Engen dwight.engen at oracle.com
Fri May 3 16:04:07 UTC 2013


Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
 src/lxc/confile.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index d0a404f..fbae861 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -782,12 +782,6 @@ static int config_network_ipv6_gateway(const char *key, const char *value,
 	if (!netdev)
 		return -1;
 
-	gw = malloc(sizeof(*gw));
-	if (!gw) {
-		SYSERROR("failed to allocate ipv6 gateway address");
-		return -1;
-	}
-
 	if (!value) {
 		ERROR("no ipv6 gateway address specified");
 		return -1;
@@ -797,6 +791,12 @@ static int config_network_ipv6_gateway(const char *key, const char *value,
 		netdev->ipv6_gateway = NULL;
 		netdev->ipv6_gateway_auto = true;
 	} else {
+		gw = malloc(sizeof(*gw));
+		if (!gw) {
+			SYSERROR("failed to allocate ipv6 gateway address");
+			return -1;
+		}
+
 		if (!inet_pton(AF_INET6, value, gw)) {
 			SYSERROR("invalid ipv6 gateway address: %s", value);
 			free(gw);
-- 
1.8.1.4





More information about the lxc-devel mailing list