Fix memory leak for probableWALfiles in db_impl.cc
Summary: using unique_ptr to have automatic delete for probableWALfiles in db_impl.cc Test Plan: make Reviewers: sheki, dhruba Reviewed By: sheki CC: leveldb Differential Revision: https://reviews.facebook.net/D10083
This commit is contained in:
parent
db8b404120
commit
94d86b25a9
@ -894,8 +894,9 @@ Status DBImpl::GetUpdatesSince(SequenceNumber seq,
|
||||
}
|
||||
// std::shared_ptr would have been useful here.
|
||||
|
||||
std::vector<LogFile>* probableWALFiles = new std::vector<LogFile>();
|
||||
s = FindProbableWALFiles(&walFiles, probableWALFiles, seq);
|
||||
std::unique_ptr<std::vector<LogFile>> probableWALFiles(
|
||||
new std::vector<LogFile>());
|
||||
s = FindProbableWALFiles(&walFiles, probableWALFiles.get(), seq);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
@ -904,7 +905,7 @@ Status DBImpl::GetUpdatesSince(SequenceNumber seq,
|
||||
&options_,
|
||||
storage_options_,
|
||||
seq,
|
||||
probableWALFiles,
|
||||
std::move(probableWALFiles),
|
||||
&last_flushed_sequence_));
|
||||
iter->get()->Next();
|
||||
return iter->get()->status();
|
||||
|
@ -9,18 +9,18 @@ TransactionLogIteratorImpl::TransactionLogIteratorImpl(
|
||||
const Options* options,
|
||||
const StorageOptions& soptions,
|
||||
SequenceNumber& seq,
|
||||
std::vector<LogFile>* files,
|
||||
std::unique_ptr<std::vector<LogFile>> files,
|
||||
SequenceNumber const * const lastFlushedSequence) :
|
||||
dbname_(dbname),
|
||||
options_(options),
|
||||
soptions_(soptions),
|
||||
startingSequenceNumber_(seq),
|
||||
files_(files),
|
||||
files_(std::move(files)),
|
||||
started_(false),
|
||||
isValid_(false),
|
||||
currentFileIndex_(0),
|
||||
lastFlushedSequence_(lastFlushedSequence) {
|
||||
assert(files_ != nullptr);
|
||||
assert(files_.get() != nullptr);
|
||||
assert(lastFlushedSequence_);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ bool TransactionLogIteratorImpl::Valid() {
|
||||
}
|
||||
|
||||
void TransactionLogIteratorImpl::Next() {
|
||||
LogFile currentLogFile = files_->at(currentFileIndex_);
|
||||
LogFile currentLogFile = files_.get()->at(currentFileIndex_);
|
||||
LogReporter reporter = NewLogReporter(currentLogFile.logNumber);
|
||||
|
||||
// First seek to the given seqNo. in the current file.
|
||||
@ -134,9 +134,9 @@ void TransactionLogIteratorImpl::Next() {
|
||||
}
|
||||
|
||||
if (openNextFile) {
|
||||
if (currentFileIndex_ < files_->size() - 1) {
|
||||
if (currentFileIndex_ < files_.get()->size() - 1) {
|
||||
++currentFileIndex_;
|
||||
Status status = OpenLogReader(files_->at(currentFileIndex_));
|
||||
Status status = OpenLogReader(files_.get()->at(currentFileIndex_));
|
||||
if (!status.ok()) {
|
||||
isValid_ = false;
|
||||
currentStatus_ = status;
|
||||
|
@ -30,14 +30,9 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
|
||||
const Options* options,
|
||||
const StorageOptions& soptions,
|
||||
SequenceNumber& seqNum,
|
||||
std::vector<LogFile>* files,
|
||||
std::unique_ptr<std::vector<LogFile>> files,
|
||||
SequenceNumber const * const lastFlushedSequence);
|
||||
|
||||
virtual ~TransactionLogIteratorImpl() {
|
||||
// TODO move to cc file.
|
||||
delete files_;
|
||||
}
|
||||
|
||||
virtual bool Valid();
|
||||
|
||||
virtual void Next();
|
||||
@ -51,7 +46,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
|
||||
const Options* options_;
|
||||
const StorageOptions& soptions_;
|
||||
const uint64_t startingSequenceNumber_;
|
||||
const std::vector<LogFile>* files_;
|
||||
std::unique_ptr<std::vector<LogFile>> files_;
|
||||
bool started_;
|
||||
bool isValid_; // not valid when it starts of.
|
||||
Status currentStatus_;
|
||||
|
Loading…
Reference in New Issue
Block a user