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
This commit is contained in:
Yueh-Hsuan Chiang 2015-08-11 10:55:27 -07:00
parent a1581eca87
commit b47d65b315
2 changed files with 7 additions and 17 deletions

View File

@ -85,23 +85,14 @@ class ReverseBytewiseComparatorImpl : public BytewiseComparatorImpl {
}// namespace }// 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() { const Comparator* BytewiseComparator() {
port::InitOnce(&once, InitModule); static BytewiseComparatorImpl bytewise;
return bytewise.get(); return &bytewise;
} }
const Comparator* ReverseBytewiseComparator() { const Comparator* ReverseBytewiseComparator() {
port::InitOnce(&once, InitModule); static ReverseBytewiseComparatorImpl rbytewise;
return rbytewise.get(); return &rbytewise;
} }
} // namespace rocksdb } // namespace rocksdb

View File

@ -149,14 +149,13 @@ ThreadLocalPtr::StaticMeta::StaticMeta() : next_instance_id_(0) {
// of memory backing destructed statically-scoped objects. Perhaps // of memory backing destructed statically-scoped objects. Perhaps
// registering with atexit(3) would be more robust. // registering with atexit(3) would be more robust.
// //
// This is not required on Windows. // This is not required on Windows. Also, it's not required on Mac
#if !defined(OS_WIN) // as ThreadLocal is not supported in Mac.
#if !defined(OS_MACOSX) && !defined(IOS_CROSS_COMPILE) && !defined(OS_WIN)
static struct A { static struct A {
~A() { ~A() {
#if defined(OS_MACOSX)
ThreadData* tls_ = ThreadData* tls_ =
static_cast<ThreadData*>(pthread_getspecific(Instance()->pthread_key_)); static_cast<ThreadData*>(pthread_getspecific(Instance()->pthread_key_));
#endif
if (tls_) { if (tls_) {
OnThreadExit(tls_); OnThreadExit(tls_);
} }