net/tap: fix file descriptor leak on error
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 6 Nov 2018 19:30:04 +0000 (11:30 -0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 14 Nov 2018 01:14:09 +0000 (02:14 +0100)
If netlink socket setup fails the file descriptor was leaked.

Coverity issue: 257040
Fixes: 7c25284e30c2 ("net/tap: add netlink back-end for flow API")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Keith Wiles <keith.wiles@intel.com>
drivers/net/tap/tap_netlink.c

index 6cb5100..14bbbec 100644 (file)
@@ -51,14 +51,17 @@ tap_nl_init(uint32_t nl_groups)
        }
        if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sndbuf_size, sizeof(int))) {
                TAP_LOG(ERR, "Unable to set socket buffer send size");
+               close(fd);
                return -1;
        }
        if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf_size, sizeof(int))) {
                TAP_LOG(ERR, "Unable to set socket buffer receive size");
+               close(fd);
                return -1;
        }
        if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
                TAP_LOG(ERR, "Unable to bind to the netlink socket");
+               close(fd);
                return -1;
        }
        return fd;