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
main
Yueh-Hsuan Chiang 10 years ago
parent a1581eca87
commit b47d65b315
  1. 17
      util/comparator.cc
  2. 7
      util/thread_local.cc

@ -85,23 +85,14 @@ class ReverseBytewiseComparatorImpl : public BytewiseComparatorImpl {
}// namespace
static port::OnceType once = LEVELDB_ONCE_INIT;
static std::unique_ptr<const Comparator> bytewise;
static std::unique_ptr<const Comparator> 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

@ -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<ThreadData*>(pthread_getspecific(Instance()->pthread_key_));
#endif
if (tls_) {
OnThreadExit(tls_);
}

Loading…
Cancel
Save