From: Karel Zak Date: Fri, 15 May 2020 10:09:43 +0000 (+0200) Subject: libmount: (umount) fix FD leak X-Git-Tag: v2.36-rc1~101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6390860d71b63ce569f419d886b98a89e106de99;p=thirdparty%2Futil-linux.git libmount: (umount) fix FD leak References: http://github.com/karelzak/util-linux/commit/7065cc0e5312cafc5ae3e4c342f78f264300fb5f Signed-off-by: Karel Zak --- 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);