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
This commit is contained in:
Yi Wu 2017-04-28 12:33:30 -07:00
parent ebbce5b10d
commit 71acb4c122

View File

@ -150,7 +150,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch(
// TODO(agiardullo): consider adding support for reverse iteration // TODO(agiardullo): consider adding support for reverse iteration
iter->Seek(key); iter->Seek(key);
while (iter->Valid()) { while (iter->Valid()) {
const WriteEntry& entry = iter->Entry(); const WriteEntry entry = iter->Entry();
if (cmp->CompareKey(cf_id, entry.key, key) != 0) { if (cmp->CompareKey(cf_id, entry.key, key) != 0) {
break; break;
} }
@ -169,9 +169,9 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch(
iter->Prev(); iter->Prev();
} }
const Slice* entry_value = nullptr; Slice entry_value;
while (iter->Valid()) { while (iter->Valid()) {
const WriteEntry& entry = iter->Entry(); const WriteEntry entry = iter->Entry();
if (cmp->CompareKey(cf_id, entry.key, key) != 0) { if (cmp->CompareKey(cf_id, entry.key, key) != 0) {
// Unexpected error or we've reached a different next key // Unexpected error or we've reached a different next key
break; break;
@ -180,7 +180,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch(
switch (entry.type) { switch (entry.type) {
case kPutRecord: { case kPutRecord: {
result = WriteBatchWithIndexInternal::Result::kFound; result = WriteBatchWithIndexInternal::Result::kFound;
entry_value = &entry.value; entry_value = entry.value;
break; break;
} }
case kMergeRecord: { case kMergeRecord: {
@ -242,7 +242,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch(
Logger* logger = immuable_db_options.info_log.get(); Logger* logger = immuable_db_options.info_log.get();
if (merge_operator) { if (merge_operator) {
*s = MergeHelper::TimedFullMerge(merge_operator, key, entry_value, *s = MergeHelper::TimedFullMerge(merge_operator, key, &entry_value,
merge_context->GetOperands(), value, merge_context->GetOperands(), value,
logger, statistics, env); logger, statistics, env);
} else { } else {
@ -255,7 +255,7 @@ WriteBatchWithIndexInternal::Result WriteBatchWithIndexInternal::GetFromBatch(
} }
} else { // nothing to merge } else { // nothing to merge
if (result == WriteBatchWithIndexInternal::Result::kFound) { // PUT if (result == WriteBatchWithIndexInternal::Result::kFound) { // PUT
value->assign(entry_value->data(), entry_value->size()); value->assign(entry_value.data(), entry_value.size());
} }
} }
} }