[Libguestfs] [PATCH] daemon: use CLEANUP_CLOSE

Pino Toscano ptoscano at redhat.com
Fri Aug 8 14:03:53 UTC 2014


---
 daemon/checksum.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/daemon/checksum.c b/daemon/checksum.c
index 019c04c..6ec48c0 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -72,10 +72,8 @@ checksum (const char *csumtype, int fd)
   size_t len;
 
   program = program_of_csum (csumtype);
-  if (program == NULL) {
-    close (fd);
+  if (program == NULL)
     return NULL;
-  }
 
   pulse_mode_start ();
 
@@ -100,7 +98,7 @@ checksum (const char *csumtype, int fd)
 char *
 do_checksum (const char *csumtype, const char *path)
 {
-  int fd;
+  CLEANUP_CLOSE int fd = -1;
 
   CHROOT_IN;
   fd = open (path, O_RDONLY|O_CLOEXEC);
@@ -117,7 +115,7 @@ do_checksum (const char *csumtype, const char *path)
 char *
 do_checksum_device (const char *csumtype, const char *device)
 {
-  int fd;
+  CLEANUP_CLOSE int fd = -1;
 
   fd = open (device, O_RDONLY|O_CLOEXEC);
   if (fd == -1) {
-- 
1.9.3




More information about the Libguestfs mailing list