From 855aaf414af3b8c8ca1f722a589fd251cc8317ee Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 8 Mar 2012 11:32:43 +0000 Subject: proto: Close file along error and cancel paths (found by Coverity). Error: RESOURCE_LEAK: /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1125: open_fn: Calling opening function "open". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1125: var_assign: Assigning: "fd" = handle returned from "open(filename, 833, 438)". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1133: noescape: Variable "fd" is not closed or saved in function "xwrite". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1146: leaked_handle: Handle variable "fd" going out of scope leaks the handle. /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1173: leaked_handle: Handle variable "fd" going out of scope leaks the handle. --- src/proto.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/proto.c b/src/proto.c index 4a558ef7..ee949dd6 100644 --- a/src/proto.c +++ b/src/proto.c @@ -1133,16 +1133,20 @@ guestfs___recv_file (guestfs_h *g, const char *filename) if (xwrite (fd, buf, r) == -1) { perrorf (g, "%s: write", filename); free (buf); + close (fd); goto cancel; } free (buf); - if (g->user_cancel) + if (g->user_cancel) { + close (fd); goto cancel; + } } if (r == -1) { error (g, _("%s: error in chunked encoding"), filename); + close (fd); return -1; } -- cgit