From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 05/16] tap: Resource leak, CWE-404 Date: Tue, 05 Apr 2022 19:05:03 +0200 Message-ID: <20220405170514.2963773-6-sbrivio@redhat.com> In-Reply-To: <20220405170514.2963773-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5505931123367728803==" --===============5505931123367728803== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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; } -- 2.35.1 --===============5505931123367728803==--