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.
This commit is contained in:
Richard W.M. Jones
2012-03-08 11:32:43 +00:00
parent 618954a6b0
commit 855aaf414a

View File

@@ -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;
}