summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2020-09-22 14:17:15 +0200
committerPhilippe Guibert <philippe.guibert@6wind.com>2020-09-22 21:09:13 +0200
commit7529bf8f05d574ef465c532ba2ca3e07c44ba60d (patch)
tree8fe80e6187dbe989a38d03a3f0d69c4e2ef6e667
parente2dcd0c2c5fe2a45a9bcd34a9cdce8a9059e0ec7 (diff)
zebra: fix fd going out of scope leaks the handle
the file descriptor is closed if it has been locally created. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
-rw-r--r--zebra/zebra_netns_id.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c
index 79121bb086..a27b136dfc 100644
--- a/zebra/zebra_netns_id.c
+++ b/zebra/zebra_netns_id.c
@@ -185,7 +185,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
if (sock < 0) {
flog_err_sys(EC_LIB_SOCKET, "netlink( %u) socket() error: %s",
sock, safe_strerror(errno));
- if (fd_param == -1)
+ if (netnspath)
close(fd);
return NS_UNKNOWN;
}
@@ -199,7 +199,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
"netlink( %u) socket() bind error: %s", sock,
safe_strerror(errno));
close(sock);
- if (fd_param == -1)
+ if (netnspath)
close(fd);
return NS_UNKNOWN;
}
@@ -222,7 +222,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
ret = send_receive(sock, nlh, seq, buf);
if (ret < 0) {
close(sock);
- if (fd_param == -1)
+ if (netnspath)
close(fd);
return NS_UNKNOWN;
}
@@ -267,7 +267,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
"netlink( %u) recvfrom() error 2 when reading: %s",
fd, safe_strerror(errno));
close(sock);
- if (fd_param == -1)
+ if (netnspath)
close(fd);
if (errno == ENOTSUP) {
zlog_debug("NEWNSID locally generated");
@@ -289,7 +289,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
ret = send_receive(sock, nlh, seq, buf);
if (ret < 0) {
close(sock);
- if (fd_param == -1)
+ if (netnspath)
close(fd);
return NS_UNKNOWN;
}
@@ -321,7 +321,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
} while (len != 0 && ret == 0);
}
- if (fd_param == -1)
+ if (netnspath)
close(fd);
close(sock);
return return_nsid;