[virt-tools-list] [vhostmd PATCH 16/18] vhostmd: Check for valide file handle before calling close

Jim Fehlig jfehlig at suse.com
Wed Jan 15 22:07:47 UTC 2020


>From coverity scan

vhostmd-1.1/vhostmd/vhostmd.c:778: var_tested_neg: Assigning: "fd" = a negative value.
vhostmd-1.1/vhostmd/vhostmd.c:845: negative_returns: "fd" is passed to a parameter that cannot be negative.
  843|      free(dir);
  844|      free(buf);
  845|->    close(fd);
  846|      return -1;
  847|   }

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
 vhostmd/vhostmd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
index 1600a87..1395bc5 100644
--- a/vhostmd/vhostmd.c
+++ b/vhostmd/vhostmd.c
@@ -860,7 +860,8 @@ static int metrics_disk_create(void)
  error:
    free(dir);
    free(buf);
-   close(fd);
+   if (fd != -1)
+       close(fd);
    return -1;
 }
 
-- 
2.16.4





More information about the virt-tools-list mailing list