From d0453c02545c825810fec6e5874c55d7ac5ec678 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 8 Mar 2012 11:44:31 +0000 Subject: daemon: proto: Close fd along error paths (found by Coverity). Error: RESOURCE_LEAK: /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:894: open_fn: Calling opening function "open". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:894: var_assign: Assigning: "fd" = handle returned from "open(filename, 0)". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:903: noescape: Variable "fd" is not closed or saved in function "read". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:911: leaked_handle: Handle variable "fd" going out of scope leaks the handle. /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:918: leaked_handle: Handle variable "fd" going out of scope leaks the handle. --- src/proto.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/proto.c b/src/proto.c index ee949dd6..1ab8d187 100644 --- a/src/proto.c +++ b/src/proto.c @@ -908,6 +908,7 @@ guestfs___send_file (guestfs_h *g, const char *filename) if (err < 0) { if (err == -2) /* daemon sent cancellation */ send_file_cancellation (g); + close (fd); return err; } } @@ -915,6 +916,7 @@ guestfs___send_file (guestfs_h *g, const char *filename) if (r == -1) { perrorf (g, "read: %s", filename); send_file_cancellation (g); + close (fd); return -1; } @@ -922,6 +924,7 @@ guestfs___send_file (guestfs_h *g, const char *filename) error (g, _("operation cancelled by user")); g->last_errnum = EINTR; send_file_cancellation (g); + close (fd); return -1; } -- cgit