Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
fix(asan): memory leak in local_service.cpp (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao liwei authored Apr 26, 2020
1 parent d790be2 commit ce5fad4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/dist/block_service/local/local_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,16 @@ dsn::task_ptr local_file_object::read(const read_request &req,
}

dinfo("read file(%s), size = %ld", file_name().c_str(), total_sz);
std::shared_ptr<char> buf = std::shared_ptr<char>(new char[total_sz + 1]);
std::string buf;
buf.reserve(total_sz + 1);
std::ifstream fin(file_name(), std::ifstream::in);
if (!fin.is_open()) {
resp.err = ERR_FS_INTERNAL;
} else {
fin.seekg(static_cast<int64_t>(req.remote_pos), fin.beg);
fin.read(buf.get(), total_sz);
buf.get()[fin.gcount()] = '\0';
resp.buffer.assign(std::move(buf), 0, fin.gcount());
fin.read((char *)buf.c_str(), total_sz);
buf[fin.gcount()] = '\0';
resp.buffer = blob::create_from_bytes(std::move(buf));
}
fin.close();
}
Expand Down

0 comments on commit ce5fad4

Please sign in to comment.