Skip to content

Commit

Permalink
filesystem: Double close (USE_AFTER_FREE)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
adrianreber authored and avagin committed Oct 20, 2020
1 parent 38246bf commit 2a4c4bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion criu/filesystems.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion criu/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,21 @@ 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;
DIR *fdir = NULL;
struct dirent *de;

fdir = fdopendir(dirfd);
if (!fdir)
if (!fdir) {
close_safe(&dirfd);
return -1;
}

while ((de = readdir(fdir))) {
if (dir_dots(de))
Expand Down

0 comments on commit 2a4c4bf

Please sign in to comment.