filesystem: Double close (USE_AFTER_FREE)

CID 226484 (#1 of 1): Double close (USE_AFTER_FREE)
 Calling close(int) closes handle fd which has already been closed.

Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:
Adrian Reber 2020-09-28 07:24:02 +00:00 committed by Andrei Vagin
parent 38246bf554
commit 2a4c4bf2fc
2 changed files with 7 additions and 2 deletions

View file

@ -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;

View file

@ -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))