ipvrf: Fix error path of vrf_switch()
Apart from trying to close(-1), this also leaked memory. Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
parent
3e587d9f43
commit
6ac5943bdd
|
|
@ -372,12 +372,12 @@ static int vrf_switch(const char *name)
|
||||||
|
|
||||||
/* -1 on length to add '/' to the end */
|
/* -1 on length to add '/' to the end */
|
||||||
if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
|
if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
|
||||||
return -1;
|
goto out;
|
||||||
|
|
||||||
if (vrf_path(vpath, sizeof(vpath)) < 0) {
|
if (vrf_path(vpath, sizeof(vpath)) < 0) {
|
||||||
fprintf(stderr, "Failed to get base cgroup path: %s\n",
|
fprintf(stderr, "Failed to get base cgroup path: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if path already ends in netns then don't add it again */
|
/* 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());
|
snprintf(pid, sizeof(pid), "%d", getpid());
|
||||||
if (write(fd, pid, strlen(pid)) < 0) {
|
if (write(fd, pid, strlen(pid)) < 0) {
|
||||||
fprintf(stderr, "Failed to join cgroup\n");
|
fprintf(stderr, "Failed to join cgroup\n");
|
||||||
goto out;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
out2:
|
||||||
|
close(fd);
|
||||||
out:
|
out:
|
||||||
free(mnt);
|
free(mnt);
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue