diff --git a/criu/filesystems.c b/criu/filesystems.c index d76b182918..fc53f4e5d8 100644 --- a/criu/filesystems.c +++ b/criu/filesystems.c @@ -656,7 +656,6 @@ static int dump_empty_fs(struct mount_info *pm) return fd; ret = is_empty_dir(fd); - close(fd); if (ret < 0) { pr_err("%s isn't empty\n", pm->fstype->name); return -1; diff --git a/criu/util.c b/criu/util.c index a88da8d037..c610da7b3a 100644 --- a/criu/util.c +++ b/criu/util.c @@ -709,6 +709,10 @@ int is_root_user(void) return 1; } +/* + * is_empty_dir will always close the FD dirfd: either implicitly + * via closedir or explicitly in case fdopendir had failed + */ int is_empty_dir(int dirfd) { int ret = 0; @@ -716,8 +720,10 @@ int is_empty_dir(int dirfd) struct dirent *de; fdir = fdopendir(dirfd); - if (!fdir) + if (!fdir) { + close_safe(&dirfd); return -1; + } while ((de = readdir(fdir))) { if (dir_dots(de))