[Libguestfs] [PATCH 6/6] p2v: fix possible close(-1) issue

Pino Toscano ptoscano at redhat.com
Mon Mar 6 14:42:51 UTC 2017


Make sure the error handler (i.e. the code after the 'cleanup' label)
does not attempt to call close(-1), in case 'sockfd' is not initialized
yet.
---
 p2v/nbd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/p2v/nbd.c b/p2v/nbd.c
index ee21005..29ca40d 100644
--- a/p2v/nbd.c
+++ b/p2v/nbd.c
@@ -722,7 +722,8 @@ wait_for_nbd_server_to_start (const char *ipaddr, int port)
 
   result = 0;
  cleanup:
-  close (sockfd);
+  if (sockfd >= 0)
+    close (sockfd);
 
   return result;
 }
-- 
2.9.3




More information about the Libguestfs mailing list