]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Fix the valgrind error 2.6.fb v2.6
authorKai Liu <kailiu@fb.com>
Thu, 7 Nov 2013 23:46:48 +0000 (15:46 -0800)
committerKai Liu <kailiu@fb.com>
Thu, 7 Nov 2013 23:46:48 +0000 (15:46 -0800)
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

index 0871b0eb6223ad31f9bf631cbdd214762bf54ec9..6ab992bd742875a00f7738d0b51836f301ab1bbe 100644 (file)
@@ -215,12 +215,12 @@ bool TransactionLogIteratorImpl::IsBatchExpected(
 }
 
 void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) {
-  WriteBatch* batch = new WriteBatch();
-  WriteBatchInternal::SetContents(batch, record);
+  std::unique_ptr<WriteBatch> 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();
 }