[Libguestfs] [PATCH] make-fs: do not leak the fd from mkstemp
Richard W.M. Jones
rjones at redhat.com
Mon Jul 28 18:09:05 UTC 2014
On Mon, Jul 28, 2014 at 07:53:20PM +0200, Pino Toscano wrote:
> ---
> make-fs/make-fs.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
> index 9c11fef..406aa1d 100644
> --- a/make-fs/make-fs.c
> +++ b/make-fs/make-fs.c
> @@ -382,15 +382,18 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char **ifmt_rtn)
> char line[256];
> size_t len;
> CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g);
> + int fd;
>
> if (asprintf (&tmpfile, "%s/makefsXXXXXX", tmpdir) == -1) {
> perror ("asprintf");
> return -1;
> }
> - if (mkstemp (tmpfile) == -1) {
> + fd = mkstemp (tmpfile);
> + if (fd == -1) {
> perror (tmpfile);
> return -1;
> }
> + close (fd);
>
> if (stat (input, &statbuf) == -1) {
> perror (input);
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
More information about the Libguestfs
mailing list