From 71acb4c1223ef6c8224f1129f96916f812c3290a Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Fri, 28 Apr 2017 12:33:30 -0700 Subject: [PATCH] Fix WriteBatchWithIndex address use after scope error Summary: Fix use after scope error caught by ASAN. Closes https://github.com/facebook/rocksdb/pull/2228 Differential Revision: D4968028 Pulled By: yiwu-arbug fbshipit-source-id: a2a266c98634237494ab4fb2d666bc938127aeb2 --- .../write_batch_with_index_internal.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utilities/write_batch_with_index/write_batch_with_index_internal.cc b/utilities/write_batch_with_index/write_batch_with_index_internal.cc index eaf1dde09..aad545f16 100644 --- a/utilities/write_batch_with_index/write_batch_with_index_internal.cc +++ b/utilities/write_batch_with_index/write_batch_with_index_internal.cc @@ -150,7 +150,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch( // TODO(agiardullo): consider adding support for reverse iteration iter->Seek(key); while (iter->Valid()) { - const WriteEntry& entry = iter->Entry(); + const WriteEntry entry = iter->Entry(); if (cmp->CompareKey(cf_id, entry.key, key) != 0) { break; } @@ -169,9 +169,9 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch( iter->Prev(); } - const Slice* entry_value = nullptr; + Slice entry_value; while (iter->Valid()) { - const WriteEntry& entry = iter->Entry(); + const WriteEntry entry = iter->Entry(); if (cmp->CompareKey(cf_id, entry.key, key) != 0) { // Unexpected error or we've reached a different next key break; @@ -180,7 +180,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch( switch (entry.type) { case kPutRecord: { result = WriteBatchWithIndexInternal::Result::kFound; - entry_value = &entry.value; + entry_value = entry.value; break; } case kMergeRecord: { @@ -242,7 +242,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch( Logger* logger = immuable_db_options.info_log.get(); if (merge_operator) { - *s = MergeHelper::TimedFullMerge(merge_operator, key, entry_value, + *s = MergeHelper::TimedFullMerge(merge_operator, key, &entry_value, merge_context->GetOperands(), value, logger, statistics, env); } else { @@ -255,7 +255,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch( } } else { // nothing to merge if (result == WriteBatchWithIndexInternal::Result::kFound) { // PUT - value->assign(entry_value->data(), entry_value->size()); + value->assign(entry_value.data(), entry_value.size()); } } }