Skip to content

Commit

Permalink
Merge pull request #2415 from ehds/fix-unix-dir-close
Browse files Browse the repository at this point in the history
fix DirReaderPosix close same fd twice
  • Loading branch information
lorinlee committed Oct 18, 2023
2 parents 12d0728 + 1245d5c commit ba5271a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/butil/files/dir_reader_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class DirReaderUnix {
}

~DirReaderUnix() {
if (fd_ >= 0) {
if (IGNORE_EINTR(close(fd_)))
RAW_LOG(ERROR, "Failed to close directory handle");
}
if(NULL != dir_){
closedir(dir_);
if (NULL != dir_) {
if (IGNORE_EINTR(closedir(dir_)) == 0) { // this implicitly closes fd_
dir_ = NULL;
} else {
RAW_LOG(ERROR, "Failed to close directory.");
}
}
}

bool IsValid() const {
return fd_ >= 0;
return dir_ != NULL;
}

// Move to the next entry returning false if the iteration is complete.
Expand Down

0 comments on commit ba5271a

Please sign in to comment.