]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: fix fd going out of scope leaks the handle
authorPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 22 Sep 2020 12:17:15 +0000 (14:17 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 23 Sep 2020 12:03:12 +0000 (14:03 +0200)
the file descriptor is closed if it has been locally created.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
zebra/zebra_netns_id.c

index 79121bb0861c2fc69f975629bb8cfd2027ea21cf..a27b136dfc43281122bf81cd55233c3ac17aed4c 100644 (file)
@@ -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;