Blame SOURCES/0079-ipvrf-Fix-error-path-of-vrf_switch.patch

99be8f
From 7ea6dbec34ae5166dd93fd4dbfcab35512e86e94 Mon Sep 17 00:00:00 2001
99be8f
From: Andrea Claudi <aclaudi@redhat.com>
99be8f
Date: Mon, 29 Apr 2019 20:07:22 +0200
99be8f
Subject: [PATCH] ipvrf: Fix error path of vrf_switch()
99be8f
99be8f
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
99be8f
Upstream Status: iproute2.git commit 6ac5943bdd5ac
99be8f
99be8f
commit 6ac5943bdd5ac5bb8c22b99f5a1d5907ebbcae2b
99be8f
Author: Phil Sutter <phil@nwl.cc>
99be8f
Date:   Thu Aug 17 19:09:27 2017 +0200
99be8f
99be8f
    ipvrf: Fix error path of vrf_switch()
99be8f
99be8f
    Apart from trying to close(-1), this also leaked memory.
99be8f
99be8f
    Signed-off-by: Phil Sutter <phil@nwl.cc>
99be8f
---
99be8f
 ip/ipvrf.c | 9 +++++----
99be8f
 1 file changed, 5 insertions(+), 4 deletions(-)
99be8f
99be8f
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
99be8f
index 0f611b44b78ab..ae3b48fa81996 100644
99be8f
--- a/ip/ipvrf.c
99be8f
+++ b/ip/ipvrf.c
99be8f
@@ -369,12 +369,12 @@ static int vrf_switch(const char *name)
99be8f
 
99be8f
 	/* -1 on length to add '/' to the end */
99be8f
 	if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
99be8f
-		return -1;
99be8f
+		goto out;
99be8f
 
99be8f
 	if (vrf_path(vpath, sizeof(vpath)) < 0) {
99be8f
 		fprintf(stderr, "Failed to get base cgroup path: %s\n",
99be8f
 			strerror(errno));
99be8f
-		return -1;
99be8f
+		goto out;
99be8f
 	}
99be8f
 
99be8f
 	/* if path already ends in netns then don't add it again */
99be8f
@@ -425,13 +425,14 @@ static int vrf_switch(const char *name)
99be8f
 	snprintf(pid, sizeof(pid), "%d", getpid());
99be8f
 	if (write(fd, pid, strlen(pid)) < 0) {
99be8f
 		fprintf(stderr, "Failed to join cgroup\n");
99be8f
-		goto out;
99be8f
+		goto out2;
99be8f
 	}
99be8f
 
99be8f
 	rc = 0;
99be8f
+out2:
99be8f
+	close(fd);
99be8f
 out:
99be8f
 	free(mnt);
99be8f
-	close(fd);
99be8f
 
99be8f
 	return rc;
99be8f
 }
99be8f
-- 
99be8f
2.20.1
99be8f