From 48bc843d6e406a142b5b07e57a3d7d242c2bed03 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 5 Apr 2022 07:14:51 +0200 Subject: [PATCH] tap: Resource leak, CWE-404 Reported by Coverity. Signed-off-by: Stefano Brivio --- tap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tap.c b/tap.c index e4dd804..8310891 100644 --- a/tap.c +++ b/tap.c @@ -899,8 +899,11 @@ static int tap_ns_tun(void *arg) if (ns_enter(c) || (tun_ns_fd = open("/dev/net/tun", flags)) < 0 || ioctl(tun_ns_fd, TUNSETIFF, &ifr) || - !(c->pasta_ifi = if_nametoindex(c->pasta_ifn))) + !(c->pasta_ifi = if_nametoindex(c->pasta_ifn))) { + if (tun_ns_fd != -1) + close(tun_ns_fd); tun_ns_fd = -1; + } return 0; }