diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-03-08 11:32:43 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-03-08 13:21:58 +0000 |
commit | 855aaf414af3b8c8ca1f722a589fd251cc8317ee (patch) | |
tree | 1d98d81c0afc11b072c5873b921e449aa48d9b29 | |
parent | 618954a6b0adc3e0eacda799b88f020c801a0106 (diff) | |
download | libguestfs-855aaf414af3b8c8ca1f722a589fd251cc8317ee.tar.gz libguestfs-855aaf414af3b8c8ca1f722a589fd251cc8317ee.tar.xz libguestfs-855aaf414af3b8c8ca1f722a589fd251cc8317ee.zip |
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.
-rw-r--r-- | src/proto.c | 6 |
1 files changed, 5 insertions, 1 deletions
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; } |