From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [PATCH 3/4] net/tap: fix file descriptor leak on error Date: Tue, 6 Nov 2018 11:30:04 -0800 Message-ID: <20181106193005.5383-4-stephen@networkplumber.org> References: <20181106193005.5383-1-stephen@networkplumber.org> Cc: Stephen Hemminger To: dev@dpdk.org Return-path: Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id B0A5B2C52 for ; Tue, 6 Nov 2018 20:30:11 +0100 (CET) Received: by mail-pg1-f195.google.com with SMTP id 32-v6so6259745pgu.2 for ; Tue, 06 Nov 2018 11:30:11 -0800 (PST) In-Reply-To: <20181106193005.5383-1-stephen@networkplumber.org> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If netlink socket setup fails the file descriptor was leaked. Coverity issue: 257040 Fixes: 7c25284e30c2 ("net/tap: add netlink back-end for flow API") Signed-off-by: Stephen Hemminger --- drivers/net/tap/tap_netlink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c index 6cb510092218..14bbbec754f6 100644 --- a/drivers/net/tap/tap_netlink.c +++ b/drivers/net/tap/tap_netlink.c @@ -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; -- 2.17.1