From 37e97b129795fdd02418ce67c3b2b63445450423 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Fri, 3 May 2013 14:25:12 -0700 Subject: [PATCH] Fix invalid-read to freed memory in ttl-iterator Summary: value function in ttl-iterator was returning string which would have been freed before its usage as a slice. Thanks valgrind! Test Plan: valgrind ./ttl_test Reviewers: dhruba, haobo, sheki, vamsi Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D10635 --- utilities/ttl/db_ttl.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utilities/ttl/db_ttl.cc b/utilities/ttl/db_ttl.cc index 78ddf94f1..c24719582 100644 --- a/utilities/ttl/db_ttl.cc +++ b/utilities/ttl/db_ttl.cc @@ -54,7 +54,9 @@ class TtlIterator : public Iterator { Slice value() const { assert(iter_->value().size() >= (unsigned)ts_len_); - return std::string(iter_->value().data(), iter_->value().size() - ts_len_); + Slice trimmed_value = iter_->value(); + trimmed_value.size_ -= ts_len_; + return trimmed_value; } Status status() const {