diff options
author | Sami Kerola | 2017-04-06 23:11:16 +0200 |
---|---|---|
committer | Karel Zak | 2017-04-10 15:40:40 +0200 |
commit | a0a32456c8d9b24e3df1a35d51ca67e53f791cd9 (patch) | |
tree | 5a3ed1a0f513f8c71a018627a35e1df2230edbfa /libmount | |
parent | fincore: fix file descriptor leak (diff) | |
download | kernel-qcow2-util-linux-a0a32456c8d9b24e3df1a35d51ca67e53f791cd9.tar.gz kernel-qcow2-util-linux-a0a32456c8d9b24e3df1a35d51ca67e53f791cd9.tar.xz kernel-qcow2-util-linux-a0a32456c8d9b24e3df1a35d51ca67e53f791cd9.zip |
libmount: fix file descriptor leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'libmount')
-rw-r--r-- | libmount/src/utils.c | 11 |
1 files 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; } /** |