From: Lucian Grijincu Date: Tue, 15 Sep 2015 22:54:00 +0000 (-0700) Subject: folly: async: fix SIOF in test X-Git-Tag: deprecate-dynamic-initializer~400 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=062f90e9452449cde8df256cfb01ae95b51b0e18;p=folly.git folly: async: fix SIOF in test Summary: avoid sillyness: ``` $ _build/opt/folly/io/async/test/async_test --gtest_list_tests ASAN:SIGSEGV ================================================================= ==3245135==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x000000583444 sp 0x7fff17ba0c40 bp 0x7fff17ba0c80 T0) #0 0x583443 in std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::operator=(std::_Rb_tree, std::_Select1st >, std::less, std::allocator > > const&) third-party2/libgcc/4.9.x/gcc-4.9-glibc-2.20-fb/024dbc3/include/c++/4.9.x/bits/stl_tree.h:1138 #1 0x583443 in std::map, std::allocator > >::operator=(std::map, std::allocator > > const&) third-party2/libgcc/4.9.x/gcc-4.9-glibc-2.20-fb/024dbc3/include/c++/4.9.x/bits/stl_map.h:295 #2 0x583443 in folly::SSLContext::setSSLLockTypes(std::map, std::allocator > >) folly/io/async/SSLContext.cpp:682 #3 0x40e028 in Initializer folly/io/async/test/AsyncSSLSocketTest2.cpp:143 #4 0x40e028 in __static_initialization_and_destruction_0 folly/io/async/test/AsyncSSLSocketTest2.cpp:146 #5 0x40e028 in _GLOBAL__sub_I__ZN5folly47AsyncSSLSocketTest2_AttachDetachSSLContext_Test10test_info_E folly/io/async/test/AsyncSSLSocketTest2.cpp:147 #6 0x66cf2e in __libc_csu_init /home/engshare/third-party2/glibc/2.20/src/glibc-2.20/csu/elf-init.c:88 #7 0x7f7145600084 in __libc_start_main (/usr/local/fbcode/gcc-4.9-glibc-2.20-fb/lib/libc.so.6+0x20084) #8 0x410be5 (/data/users/lucian/fbcode2/_build/opt/folly/io/async/test/async_test+0x410be5) AddressSanitizer can not provide additional info. AAAAAAASUMMARY: AddressSanitizer: SEGV third-party2/libgcc/4.9.x/gcc-4.9-glibc-2.20-fb/024dbc3/include/c++/4.9.x/bits/stl_tree.h:1138 std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::operator=(std::_Rb_tree, std::_Select1st >, std::less, std::allocator > > const&) ==3245135==ABORTING ``` Reviewed By: @philippv Differential Revision: D2440796 --- diff --git a/folly/gen/test/FileTest.cpp b/folly/gen/test/FileTest.cpp index ad70326c..6ee0ffe3 100644 --- a/folly/gen/test/FileTest.cpp +++ b/folly/gen/test/FileTest.cpp @@ -83,6 +83,7 @@ INSTANTIATE_TEST_CASE_P( DifferentBufferSizes, FileGenBufferedTest, ::testing::Values(0, 1, 2, 4, 8, 64, 4096)); + int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); gflags::ParseCommandLineFlags(&argc, &argv, true); diff --git a/folly/io/async/SSLContext.cpp b/folly/io/async/SSLContext.cpp index 38dddf97..7a9a198f 100644 --- a/folly/io/async/SSLContext.cpp +++ b/folly/io/async/SSLContext.cpp @@ -626,17 +626,13 @@ struct SSLLock { // SSLContext runs in such environments. // Instead of declaring a static member we "new" the static // member so that it won't be destructed on exit(). -static std::map* lockTypesInst = - new std::map(); - -static std::unique_ptr* locksInst = - new std::unique_ptr(); - static std::unique_ptr& locks() { + static auto locksInst = new std::unique_ptr(); return *locksInst; } static std::map& lockTypes() { + static auto lockTypesInst = new std::map(); return *lockTypesInst; } diff --git a/folly/io/async/test/AsyncSSLSocketTest2.cpp b/folly/io/async/test/AsyncSSLSocketTest2.cpp index 5f4818ee..b7026d9e 100644 --- a/folly/io/async/test/AsyncSSLSocketTest2.cpp +++ b/folly/io/async/test/AsyncSSLSocketTest2.cpp @@ -20,6 +20,7 @@ #include #include +#include using std::string; using std::vector; @@ -127,21 +128,15 @@ TEST(AsyncSSLSocketTest2, AttachDetachSSLContext) { eventBase.loop(); } +} // folly + +int main(int argc, char *argv[]) { + signal(SIGPIPE, SIG_IGN); + folly::SSLContext::setSSLLockTypes({ + {CRYPTO_LOCK_EVP_PKEY, folly::SSLContext::LOCK_NONE}, + {CRYPTO_LOCK_SSL_SESSION, folly::SSLContext::LOCK_SPINLOCK}, + {CRYPTO_LOCK_SSL_CTX, folly::SSLContext::LOCK_NONE}}); + testing::InitGoogleTest(&argc, argv); + gflags::ParseCommandLineFlags(&argc, &argv, true); + return RUN_ALL_TESTS(); } -/////////////////////////////////////////////////////////////////////////// -// init_unit_test_suite -/////////////////////////////////////////////////////////////////////////// - -namespace { -using folly::SSLContext; -struct Initializer { - Initializer() { - signal(SIGPIPE, SIG_IGN); - SSLContext::setSSLLockTypes({ - {CRYPTO_LOCK_EVP_PKEY, SSLContext::LOCK_NONE}, - {CRYPTO_LOCK_SSL_SESSION, SSLContext::LOCK_SPINLOCK}, - {CRYPTO_LOCK_SSL_CTX, SSLContext::LOCK_NONE}}); - } -}; -Initializer initializer; -} // anonymous