Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5aee72d authored by Josh Gao's avatar Josh Gao
Browse files

Don't call fdopendir on unique_fd::get.

Transfer ownership by releasing first, instead of calling fdopendir on
unique_fd::get() and then releasing afterwards, to allow for strict
fd-ownership checks.

Test: treehugger
Change-Id: Idf8f107f8b6e4fc6bea03b9a9713d30b5c874f5a
parent e3c9030d
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -16,10 +16,11 @@ namespace dvr {
class DirectoryReader {
 public:
  explicit DirectoryReader(base::unique_fd directory_fd) {
    directory_ = fdopendir(directory_fd.get());
    int fd = directory_fd.release();
    directory_ = fdopendir(fd);
    error_ = errno;
    if (directory_ != nullptr)
      (void) directory_fd.release(); // ignore return result?
    if (directory_ == nullptr)
      close(fd);
  }

  ~DirectoryReader() {