[Libguestfs] [PATCH] daemon: use CLEANUP_CLOSE

Richard W.M. Jones rjones at redhat.com
Fri Aug 8 18:32:20 UTC 2014


On Fri, Aug 08, 2014 at 04:03:53PM +0200, Pino Toscano wrote:
> ---
>  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) {

Makes sense, ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list