Skip to content

Commit

Permalink
Need not to close fstream
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu committed Sep 17, 2021
1 parent 8fea119 commit 4569886
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/common/memory/MemoryUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ StatusOr<bool> MemoryUtils::hitsHighWatermark() {
auto usageStatus = MemoryUtils::readSysContents("/sys/fs/cgroup/memory/memory.usage_in_bytes");
NG_RETURN_IF_ERROR(usageStatus);
uint64_t usageInBytes = std::move(usageStatus).value();
total = static_cast<double>(limitInBytes);
available = static_cast<double>(limitInBytes - usageInBytes + cacheSize);
total = limitInBytes;
} else {
FileUtils::FileLineIterator iter("/proc/meminfo", &reMemAvailable);
std::vector<uint64_t> memorySize;
Expand All @@ -66,12 +66,11 @@ StatusOr<bool> MemoryUtils::hitsHighWatermark() {
}

StatusOr<uint64_t> MemoryUtils::readSysContents(const std::string& path) {
uint64_t value = 0;
std::ifstream ifs(path);
if (!ifs) {
return Status::Error("Could not open the file: %s", path.c_str());
}
SCOPE_EXIT { ifs.close(); };
uint64_t value = 0;
ifs >> value;
return value;
}
Expand Down

0 comments on commit 4569886

Please sign in to comment.