From: Kai Liu Date: Thu, 7 Nov 2013 23:46:48 +0000 (-0800) Subject: Fix the valgrind error X-Git-Tag: 2.6.fb X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bba6595b1f3f42cf79bb21c2d5b981ede1cc0063;p=rocksdb.git 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 --- 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(); }