From bba6595b1f3f42cf79bb21c2d5b981ede1cc0063 Mon Sep 17 00:00:00 2001 From: Kai Liu Date: Thu, 7 Nov 2013 15:46:48 -0800 Subject: [PATCH] Fix the valgrind error Summary: I this bug from valgrind report and found a place that may potentially leak memory. Test Plan: re-ran the valgrind and no error any more Reviewers: emayanke Reviewed By: emayanke CC: leveldb Differential Revision: https://reviews.facebook.net/D13959 --- db/transaction_log_impl.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/transaction_log_impl.cc b/db/transaction_log_impl.cc index 0871b0eb6..6ab992bd7 100644 --- a/db/transaction_log_impl.cc +++ b/db/transaction_log_impl.cc @@ -215,12 +215,12 @@ bool TransactionLogIteratorImpl::IsBatchExpected( } void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) { - WriteBatch* batch = new WriteBatch(); - WriteBatchInternal::SetContents(batch, record); + std::unique_ptr batch(new WriteBatch()); + WriteBatchInternal::SetContents(batch.get(), record); SequenceNumber expectedSeq = currentLastSeq_ + 1; // If the iterator has started, then confirm that we get continuous batches - if (started_ && !IsBatchExpected(batch, expectedSeq)) { + if (started_ && !IsBatchExpected(batch.get(), expectedSeq)) { // Seek to the batch having expected sequence number if (expectedSeq < files_->at(currentFileIndex_)->StartSequence()) { // Expected batch must lie in the previous log file @@ -233,12 +233,13 @@ void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) { return SeekToStartSequence(currentFileIndex_, true); } - currentBatchSeq_ = WriteBatchInternal::Sequence(batch); - currentLastSeq_ = currentBatchSeq_ + WriteBatchInternal::Count(batch) - 1; + currentBatchSeq_ = WriteBatchInternal::Sequence(batch.get()); + currentLastSeq_ = currentBatchSeq_ + + WriteBatchInternal::Count(batch.get()) - 1; // currentBatchSeq_ can only change here assert(currentLastSeq_ <= dbimpl_->GetLatestSequenceNumber()); - currentBatch_.reset(batch); + currentBatch_ = move(batch); isValid_ = true; currentStatus_ = Status::OK(); }