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::shared_ptr would have been useful here.
|
||||||
|
|
||||||
std::vector<LogFile>* probableWALFiles = new std::vector<LogFile>();
|
std::unique_ptr<std::vector<LogFile>> probableWALFiles(
|
||||||
s = FindProbableWALFiles(&walFiles, probableWALFiles, seq);
|
new std::vector<LogFile>());
|
||||||
|
s = FindProbableWALFiles(&walFiles, probableWALFiles.get(), seq);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -904,7 +905,7 @@ Status DBImpl::GetUpdatesSince(SequenceNumber seq,
|
|||||||
&options_,
|
&options_,
|
||||||
storage_options_,
|
storage_options_,
|
||||||
seq,
|
seq,
|
||||||
probableWALFiles,
|
std::move(probableWALFiles),
|
||||||
&last_flushed_sequence_));
|
&last_flushed_sequence_));
|
||||||
iter->get()->Next();
|
iter->get()->Next();
|
||||||
return iter->get()->status();
|
return iter->get()->status();
|
||||||
|
@ -9,18 +9,18 @@ TransactionLogIteratorImpl::TransactionLogIteratorImpl(
|
|||||||
const Options* options,
|
const Options* options,
|
||||||
const StorageOptions& soptions,
|
const StorageOptions& soptions,
|
||||||
SequenceNumber& seq,
|
SequenceNumber& seq,
|
||||||
std::vector<LogFile>* files,
|
std::unique_ptr<std::vector<LogFile>> files,
|
||||||
SequenceNumber const * const lastFlushedSequence) :
|
SequenceNumber const * const lastFlushedSequence) :
|
||||||
dbname_(dbname),
|
dbname_(dbname),
|
||||||
options_(options),
|
options_(options),
|
||||||
soptions_(soptions),
|
soptions_(soptions),
|
||||||
startingSequenceNumber_(seq),
|
startingSequenceNumber_(seq),
|
||||||
files_(files),
|
files_(std::move(files)),
|
||||||
started_(false),
|
started_(false),
|
||||||
isValid_(false),
|
isValid_(false),
|
||||||
currentFileIndex_(0),
|
currentFileIndex_(0),
|
||||||
lastFlushedSequence_(lastFlushedSequence) {
|
lastFlushedSequence_(lastFlushedSequence) {
|
||||||
assert(files_ != nullptr);
|
assert(files_.get() != nullptr);
|
||||||
assert(lastFlushedSequence_);
|
assert(lastFlushedSequence_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ bool TransactionLogIteratorImpl::Valid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TransactionLogIteratorImpl::Next() {
|
void TransactionLogIteratorImpl::Next() {
|
||||||
LogFile currentLogFile = files_->at(currentFileIndex_);
|
LogFile currentLogFile = files_.get()->at(currentFileIndex_);
|
||||||
LogReporter reporter = NewLogReporter(currentLogFile.logNumber);
|
LogReporter reporter = NewLogReporter(currentLogFile.logNumber);
|
||||||
|
|
||||||
// First seek to the given seqNo. in the current file.
|
// First seek to the given seqNo. in the current file.
|
||||||
@ -134,9 +134,9 @@ void TransactionLogIteratorImpl::Next() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (openNextFile) {
|
if (openNextFile) {
|
||||||
if (currentFileIndex_ < files_->size() - 1) {
|
if (currentFileIndex_ < files_.get()->size() - 1) {
|
||||||
++currentFileIndex_;
|
++currentFileIndex_;
|
||||||
Status status = OpenLogReader(files_->at(currentFileIndex_));
|
Status status = OpenLogReader(files_.get()->at(currentFileIndex_));
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
isValid_ = false;
|
isValid_ = false;
|
||||||
currentStatus_ = status;
|
currentStatus_ = status;
|
||||||
|
@ -30,14 +30,9 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
|
|||||||
const Options* options,
|
const Options* options,
|
||||||
const StorageOptions& soptions,
|
const StorageOptions& soptions,
|
||||||
SequenceNumber& seqNum,
|
SequenceNumber& seqNum,
|
||||||
std::vector<LogFile>* files,
|
std::unique_ptr<std::vector<LogFile>> files,
|
||||||
SequenceNumber const * const lastFlushedSequence);
|
SequenceNumber const * const lastFlushedSequence);
|
||||||
|
|
||||||
virtual ~TransactionLogIteratorImpl() {
|
|
||||||
// TODO move to cc file.
|
|
||||||
delete files_;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Valid();
|
virtual bool Valid();
|
||||||
|
|
||||||
virtual void Next();
|
virtual void Next();
|
||||||
@ -51,7 +46,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
|
|||||||
const Options* options_;
|
const Options* options_;
|
||||||
const StorageOptions& soptions_;
|
const StorageOptions& soptions_;
|
||||||
const uint64_t startingSequenceNumber_;
|
const uint64_t startingSequenceNumber_;
|
||||||
const std::vector<LogFile>* files_;
|
std::unique_ptr<std::vector<LogFile>> files_;
|
||||||
bool started_;
|
bool started_;
|
||||||
bool isValid_; // not valid when it starts of.
|
bool isValid_; // not valid when it starts of.
|
||||||
Status currentStatus_;
|
Status currentStatus_;
|
||||||
|
Loading…
Reference in New Issue
Block a user