OpenSSL の奇妙な問題に直面しています。アプリケーションを win32 サービス (ローカル サービス/ネットワーク サービスまたはシステム サービス) として実行すると、SSL_CTX_new() 関数がクラッシュするようです。
私のコードは次のようになります。
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 < 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"); //< this print shows up
ctx->sslCtx = SSL_CTX_new(mm);
// crash >HERE< before being able to print anything else
// some code to connect to server
}
本当に奇妙なことは、このアプリケーションを通常の win32 アプリとして実行すると (つまり、win32 サービス関数を呼び出さずに、別のスレッドで myclient() を実行している場合)、すべて問題なく動作することです。
私はwin7でmingw32 gcc 4.7.1でコンパイルしており、opensslを静的にリンクしています(DLLなし)。
問題を理解するための助けをいただければ幸いです。ありがとうございました!