Skip to content

Commit

Permalink
make FileReader to close fd using RAII (zilliztech#1005)
Browse files Browse the repository at this point in the history
Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian authored Dec 25, 2024
1 parent d448fd6 commit 6a691f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/io/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ struct FileReader {
}
}

~FileReader() {
if (fd_ != -1) {
close(fd_);
fd_ = -1;
}
}

int
descriptor() const {
return fd_;
Expand Down Expand Up @@ -62,13 +69,8 @@ struct FileReader {
return lseek(fd_, 0, SEEK_CUR);
}

int
close() {
return ::close(fd_);
}

private:
int fd_;
int fd_ = -1;
size_t size_;
};
} // namespace knowhere
2 changes: 0 additions & 2 deletions thirdparty/hnswlib/hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,6 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
input.read(linkLists_[i], linkListSize);
}
}

input.close();
}

void
Expand Down

0 comments on commit 6a691f6

Please sign in to comment.