From a0a32456c8d9b24e3df1a35d51ca67e53f791cd9 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Thu, 6 Apr 2017 22:11:16 +0100 Subject: [PATCH] libmount: fix file descriptor leak Signed-off-by: Sami Kerola --- 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 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; } /** -- 2.47.2