Skip to content

Commit

Permalink
fix DirReaderPosix close same fd twice
Browse files Browse the repository at this point in the history
  • Loading branch information
ehds committed Oct 17, 2023
1 parent 1a3dcdc commit 5bc5abc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/butil/files/dir_reader_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef BUTIL_FILES_DIR_READER_UNIX_H_
#define BUTIL_FILES_DIR_READER_UNIX_H_

#include <cstddef>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
Expand All @@ -42,18 +43,14 @@ class DirReaderUnix {
}

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

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

// Move to the next entry returning false if the iteration is complete.
bool Next() {
Expand Down

0 comments on commit 5bc5abc

Please sign in to comment.