]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ipvrf: Fix error path of vrf_switch()
authorPhil Sutter <phil@nwl.cc>
Thu, 17 Aug 2017 17:09:27 +0000 (19:09 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 18 Aug 2017 16:39:52 +0000 (09:39 -0700)
Apart from trying to close(-1), this also leaked memory.

Signed-off-by: Phil Sutter <phil@nwl.cc>
ip/ipvrf.c

index 0094cf8557cd7627846e075875db68427867b381..e6fad32abd956c6159efce21ee06679d5ad3948f 100644 (file)
@@ -372,12 +372,12 @@ static int vrf_switch(const char *name)
 
        /* -1 on length to add '/' to the end */
        if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
-               return -1;
+               goto out;
 
        if (vrf_path(vpath, sizeof(vpath)) < 0) {
                fprintf(stderr, "Failed to get base cgroup path: %s\n",
                        strerror(errno));
-               return -1;
+               goto out;
        }
 
        /* if path already ends in netns then don't add it again */
@@ -428,13 +428,14 @@ static int vrf_switch(const char *name)
        snprintf(pid, sizeof(pid), "%d", getpid());
        if (write(fd, pid, strlen(pid)) < 0) {
                fprintf(stderr, "Failed to join cgroup\n");
-               goto out;
+               goto out2;
        }
 
        rc = 0;
+out2:
+       close(fd);
 out:
        free(mnt);
-       close(fd);
 
        return rc;
 }