From 6390860d71b63ce569f419d886b98a89e106de99 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 15 May 2020 12:09:43 +0200 Subject: [PATCH] libmount: (umount) fix FD leak References: http://github.com/karelzak/util-linux/commit/7065cc0e5312cafc5ae3e4c342f78f264300fb5f Signed-off-by: Karel Zak --- libmount/src/context_umount.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index e1cf7c6885..c33c0964f0 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -286,13 +286,16 @@ static int lookup_umount_fs_by_statfs(struct libmnt_context *cxt, const char *tg if (!type) { struct statfs vfs; + int fd; DBG(CXT, ul_debugobj(cxt, " trying fstatfs()")); + /* O_PATH avoids triggering automount points. */ - int pathfd = open(tgt, O_PATH); - if (pathfd >= 0 && fstatfs(pathfd, &vfs) == 0) { - type = mnt_statfs_get_fstype(&vfs); - close(pathfd); + fd = open(tgt, O_PATH); + if (fd >= 0) { + if (fstatfs(fd, &vfs) == 0) + type = mnt_statfs_get_fstype(&vfs); + close(fd); } if (type) { int rc = mnt_fs_set_fstype(cxt->fs, type); -- 2.47.3