From: Sami Kerola Date: Thu, 6 Apr 2017 21:11:16 +0000 (+0100) Subject: libmount: fix file descriptor leak X-Git-Tag: v2.30-rc1~119 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a0a32456c8d9b24e3df1a35d51ca67e53f791cd9;p=thirdparty%2Futil-linux.git libmount: fix file descriptor leak Signed-off-by: Sami Kerola --- diff --git a/libmount/src/utils.c b/libmount/src/utils.c index 7e028ee021..3b27135cdb 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; } /**