summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorSteven Luong <sluong@cisco.com>2019-02-21 14:55:52 -0800
committerFlorin Coras <florin.coras@gmail.com>2019-02-22 01:25:49 +0000
commit4a310d2b50283d5553264caf50ac1aa58384468d (patch)
treef6793a8dbe742c62005ca79955dd131d1f539ce3 /src/vnet
parent296988d358cd570247dd8b9b8bd5816a856c3d30 (diff)
tapv2: coverity strikes back
while https://gerrit.fd.io/r/#/c/16590/ fixed the leaked fd which coverity reported at that time, new coverity run reports simailar leaked fd in a different goto punt path. It would be nice if coverity reported both of them at the same time. Or perhaps it did and I just missed it. Anyway, the new fix is to put the close (fd) statement prior to the return of tap_create_if routine which should catch all goto's. Change-Id: I0a51ed3710e32d5d74c9cd9b5066a667153e2f9d Signed-off-by: Steven Luong <sluong@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/devices/tap/tap.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c
index 3739561cc59..0b2ebd6b5e3 100644
--- a/src/vnet/devices/tap/tap.c
+++ b/src/vnet/devices/tap/tap.c
@@ -93,6 +93,7 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
struct vhost_memory *vhost_mem = 0;
virtio_if_t *vif = 0;
clib_error_t *err = 0;
+ int fd = -1;
if (args->id != ~0)
{
@@ -194,8 +195,6 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
after we change our net namespace */
if (args->host_namespace)
{
- int fd;
- int rc;
old_netns_fd = open ("/proc/self/ns/net", O_RDONLY);
if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1)
{
@@ -211,9 +210,7 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
args->rv = VNET_API_ERROR_NETLINK_ERROR;
goto error;
}
- rc = setns (fd, CLONE_NEWNET);
- close (fd);
- if (rc == -1)
+ if (setns (fd, CLONE_NEWNET) == -1)
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
args->error = clib_error_return_unix (0, "setns '%s'",
@@ -436,6 +433,8 @@ done:
clib_mem_free (vhost_mem);
if (old_netns_fd != -1)
close (old_netns_fd);
+ if (fd != -1)
+ close (fd);
}
int