From b47d65b315614a2f2fbcd6ff6e10610b7d9b941a Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Tue, 11 Aug 2015 10:55:27 -0700 Subject: [PATCH] Fixed Segmentation Fault in db_stress on OSX. Summary: This patch provides a simplier solution to the memory leak issue identified in patch https://reviews.facebook.net/D43677, where a static function local variable can be used instead of using a global static unique_ptr. Test Plan: run db_stress on mac Reviewers: igor, sdong, anthony, IslamAbdelRahman, maykov Reviewed By: maykov Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D43995 --- util/comparator.cc | 17 ++++------------- util/thread_local.cc | 7 +++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/util/comparator.cc b/util/comparator.cc index 5e3332737..821a2540b 100644 --- a/util/comparator.cc +++ b/util/comparator.cc @@ -85,23 +85,14 @@ class ReverseBytewiseComparatorImpl : public BytewiseComparatorImpl { }// namespace -static port::OnceType once = LEVELDB_ONCE_INIT; -static std::unique_ptr bytewise; -static std::unique_ptr rbytewise; - -static void InitModule() { - bytewise.reset(new BytewiseComparatorImpl); - rbytewise.reset(new ReverseBytewiseComparatorImpl); -} - const Comparator* BytewiseComparator() { - port::InitOnce(&once, InitModule); - return bytewise.get(); + static BytewiseComparatorImpl bytewise; + return &bytewise; } const Comparator* ReverseBytewiseComparator() { - port::InitOnce(&once, InitModule); - return rbytewise.get(); + static ReverseBytewiseComparatorImpl rbytewise; + return &rbytewise; } } // namespace rocksdb diff --git a/util/thread_local.cc b/util/thread_local.cc index 969690739..ffe636d9e 100644 --- a/util/thread_local.cc +++ b/util/thread_local.cc @@ -149,14 +149,13 @@ ThreadLocalPtr::StaticMeta::StaticMeta() : next_instance_id_(0) { // of memory backing destructed statically-scoped objects. Perhaps // registering with atexit(3) would be more robust. // - // This is not required on Windows. -#if !defined(OS_WIN) + // This is not required on Windows. Also, it's not required on Mac + // as ThreadLocal is not supported in Mac. +#if !defined(OS_MACOSX) && !defined(IOS_CROSS_COMPILE) && !defined(OS_WIN) static struct A { ~A() { -#if defined(OS_MACOSX) ThreadData* tls_ = static_cast(pthread_getspecific(Instance()->pthread_key_)); -#endif if (tls_) { OnThreadExit(tls_); }