]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (umount) fix FD leak
authorKarel Zak <kzak@redhat.com>
Fri, 15 May 2020 10:09:43 +0000 (12:09 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 15 May 2020 10:09:43 +0000 (12:09 +0200)
References: http://github.com/karelzak/util-linux/commit/7065cc0e5312cafc5ae3e4c342f78f264300fb5f
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_umount.c

index e1cf7c688530ead30df3b9609d5660eb00a09237..c33c0964f029a4e282eabfb23e2852930f00fb04 100644 (file)
@@ -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);