From 5c62eb4d06c83f21aa14244468a44c48c173493d Mon Sep 17 00:00:00 2001 From: Sascha Sommer Date: Tue, 21 Aug 2007 15:13:43 +0200 Subject: [PATCH] mount: free loop device on failure Testcase: $ mount -oloop /etc/group /mnt ioctl: LOOP_CLR_FD: Device or resource busy mount: you must specify the filesystem type $ losetup /dev/loop0 /dev/loop0: [0803]:1931929 (/etc/group) Signed-off-by: Matthias Koenig --- mount/fsprobe_volumeid.c | 5 ++++- mount/lomount.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c index 4b58e720..6b47392b 100644 --- a/mount/fsprobe_volumeid.c +++ b/mount/fsprobe_volumeid.c @@ -34,8 +34,10 @@ static char return NULL; id = volume_id_open_fd(fd); - if (!id) + if (!id) { + close(fd); return NULL; + } /* TODO: use blkdev_get_size() */ if (ioctl(fd, BLKGETSIZE64, &size) != 0) @@ -61,6 +63,7 @@ static char } volume_id_close(id); + close(fd); return value; } diff --git a/mount/lomount.c b/mount/lomount.c index ae9eb36e..ace474cb 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -398,6 +398,7 @@ del_loop (const char *device) { } if (ioctl (fd, LOOP_CLR_FD, 0) < 0) { perror ("ioctl: LOOP_CLR_FD"); + close(fd); return 1; } close (fd); -- 2.39.5