From 1b69f1e58474665914293224f88bf109c2302f3f Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Mon, 10 Jun 2013 13:28:58 -0700 Subject: [PATCH] Fix refering freed memory in earlier commit. Summary: Fix refering freed memory in earlier commit by https://reviews.facebook.net/D11181 Test Plan: make check Reviewers: haobo, sheki Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D11193 --- db/dbformat.cc | 3 +-- db/dbformat.h | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/db/dbformat.cc b/db/dbformat.cc index be48909a96..ec40bccc3a 100644 --- a/db/dbformat.cc +++ b/db/dbformat.cc @@ -44,8 +44,7 @@ std::string InternalKey::DebugString(bool hex) const { } const char* InternalKeyComparator::Name() const { - return ("leveldb.InternalKeyComparator:" + - std::string(user_comparator_->Name())).c_str(); + return name_.c_str(); } int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const { diff --git a/db/dbformat.h b/db/dbformat.h index 09af082e95..1a05166704 100644 --- a/db/dbformat.h +++ b/db/dbformat.h @@ -86,8 +86,13 @@ inline ValueType ExtractValueType(const Slice& internal_key) { class InternalKeyComparator : public Comparator { private: const Comparator* user_comparator_; + std::string name_; public: - explicit InternalKeyComparator(const Comparator* c) : user_comparator_(c) { } + explicit InternalKeyComparator(const Comparator* c) : user_comparator_(c), + name_("leveldb.InternalKeyComparator:" + + std::string(user_comparator_->Name())) { + } + virtual const char* Name() const; virtual int Compare(const Slice& a, const Slice& b) const; virtual void FindShortestSeparator(