title: OpenSSL SSL_CTX_new crash when run as win32 service
body: <p>I am facing a weird problem of OpenSSL: it seems that SSL_CTX_new() function crashes when my application is run as a win32 service (either Local Service / Network Service or System Service).</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>int main() {
     SSL_library_init();
  
     const int nLocks = CRYPTO_num_locks();
  
     ossl_mtx_pool = new mutexT* [nLocks]; // simple wrapper class over mutexes
     for(int i = 0; i &lt; nLocks; ++i)
        ossl_mtx_pool[i] = new mutexT;
  
     CRYPTO_THREADID_set_callback(ossl_threadid_function); // returns win32 thread id
     CRYPTO_set_locking_callback(ossl_locking_fun); // simple function that calls mutexT::lock/unlock)
  
     OpenSSL_add_all_algorithms();
     SSL_load_error_strings();
     ERR_load_BIO_strings();
  
     // some other app initialization here...
  
     // run win32 service thread OR just a seaparate thread
  }
  
  // called later on in the context of a different thread
  int myclient()
  {
     myCtx *ctx = new connContextT;
     const SSL_METHOD *mm = SSLv23_client_method();
     if(mm == 0) {
        // print some error whcih doesn't show up
     }   
  
     printf("I'm Here!\n"); //&lt; this print shows up       
  
     ctx-&gt;sslCtx = SSL_CTX_new(mm);
     // crash &gt;HERE&lt; before being able to print anything else
  
     // some code to connect to server
  }
  </code></pre>
  
  <p>The really weird thing is that if I run this application as a normal win32 app (i.e. not calling win32 service functions but still running myclient() in a separate thread) everything works flawless.</p>
  
  <p>I'm compiling with mingw32 gcc 4.7.1 on win7 and I'm linking openssl statically (no DLLs).</p>
  
  <p>Any help in trying to understand the problem would be greatly appreciated.
  Thank you! </p>