folly: async: fix SIOF in test
authorLucian Grijincu <lucian@fb.com>
Tue, 15 Sep 2015 22:54:00 +0000 (15:54 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Tue, 15 Sep 2015 23:20:20 +0000 (16:20 -0700)
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<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >::operator=(std::_Rb_tree<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > > 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<int, folly::SSLContext::SSLLockType, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >::operator=(std::map<int, folly::SSLContext::SSLLockType, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > > 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<int, folly::SSLContext::SSLLockType, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >) 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<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > >::operator=(std::_Rb_tree<int, std::pair<int const, folly::SSLContext::SSLLockType>, std::_Select1st<std::pair<int const, folly::SSLContext::SSLLockType> >, std::less<int>, std::allocator<std::pair<int const, folly::SSLContext::SSLLockType> > > const&)
==3245135==ABORTING
```

Reviewed By: @philippv

Differential Revision: D2440796

folly/gen/test/FileTest.cpp
folly/io/async/SSLContext.cpp
folly/io/async/test/AsyncSSLSocketTest2.cpp

index ad70326c93e77765ce9b2bf4875ee546c6625d07..6ee0ffe3cfd6106d29fc1b1fbf716b950d6e8975 100644 (file)
@@ -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);
index 38dddf971a31d880d59a20e967be6b3093a9d4ef..7a9a198f7d0582d4402bc24373858a5464c35a47 100644 (file)
@@ -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<int, SSLContext::SSLLockType>* lockTypesInst =
-  new std::map<int, SSLContext::SSLLockType>();
-
-static std::unique_ptr<SSLLock[]>* locksInst =
-  new std::unique_ptr<SSLLock[]>();
-
 static std::unique_ptr<SSLLock[]>& locks() {
+  static auto locksInst = new std::unique_ptr<SSLLock[]>();
   return *locksInst;
 }
 
 static std::map<int, SSLContext::SSLLockType>& lockTypes() {
+  static auto lockTypesInst = new std::map<int, SSLContext::SSLLockType>();
   return *lockTypesInst;
 }
 
index 5f4818ee973c69a0c9bc53c0376186f8ad755386..b7026d9e9f4c550539ccb764bb2290cda2140921 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <folly/io/async/AsyncSSLSocket.h>
 #include <folly/io/async/EventBase.h>
+#include <folly/io/async/SSLContext.h>
 
 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