[PATCH 2/2] libmount: fix file descriptor leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 libmount/src/utils.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 7e028ee02..3b27135cd 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -647,18 +647,17 @@ done:
 
 static int try_write(const char *filename)
 {
-	int fd;
+	int fd, ret = 0;
 
 	if (!filename)
 		return -EINVAL;
 
 	fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC,
 			    S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH);
-	if (fd >= 0) {
-		close(fd);
-		return 0;
-	}
-	return -errno;
+	if (fd < 0)
+		ret = -errno;
+	close(fd);
+	return ret;
 }
 
 /**
-- 
2.12.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux