mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user