Index: test/test_context.c =================================================================== --- test/test_context.c (revision 2131) +++ test/test_context.c (working copy) @@ -2212,38 +2212,36 @@ static void test_ssltunnel_digest_auth(CuTest *tc) /*****************************************************************************/ CuSuite *test_context(void) { + /* Do not destroy the TEST_POOL during the test teardown so that it is + destroyed during the 'apr_terminate' call. This change makes serf + access already freed memory and coredump in SSL-related tests. + + The reason is the global pool created during the 'ssl_init_context' + call: + + ssl_init_context() -> + Creates GLOBAL_POOL and ALLOCATOR within the GLOBAL_POOL, binds them + to the serf_ssl_context_t CONTEXT object. + + (something SSL-related happens) -> + Creates connections bound to the TEST_POOL, but also makes some + allocations using the CONTEXT->ALLOCATOR (which are done in + GLOBAL_POOL). + + apr_terminate() -> + Sequentially destroys GLOBAL_POOL and TEST_POOL. + + TEST_POOL destruction closes connections and bang, you're dead: + closing connections attempts to reclaim free memory using the + CONTEXT->ALLOCATOR. CONTEXT->ALLOCATOR is invalid at this + moment (because GLOBAL_POOL is already destroyed), so a coredump + happens. */ + CuSuite *suite = CuSuiteNew(); - CuSuiteSetSetupTeardownCallbacks(suite, test_setup, test_teardown); + CuSuiteSetSetupTeardownCallbacks(suite, test_setup, NULL); - SUITE_ADD_TEST(suite, test_serf_connection_request_create); - SUITE_ADD_TEST(suite, test_serf_connection_priority_request_create); - SUITE_ADD_TEST(suite, test_closed_connection); - SUITE_ADD_TEST(suite, test_setup_proxy); - SUITE_ADD_TEST(suite, test_keepalive_limit_one_by_one); - SUITE_ADD_TEST(suite, test_keepalive_limit_one_by_one_and_burst); - SUITE_ADD_TEST(suite, test_progress_callback); - SUITE_ADD_TEST(suite, test_request_timeout); - SUITE_ADD_TEST(suite, test_connection_large_response); - SUITE_ADD_TEST(suite, test_connection_large_request); - SUITE_ADD_TEST(suite, test_ssl_handshake); - SUITE_ADD_TEST(suite, test_ssl_trust_rootca); - SUITE_ADD_TEST(suite, test_ssl_application_rejects_cert); - SUITE_ADD_TEST(suite, test_ssl_certificate_chain_with_anchor); - SUITE_ADD_TEST(suite, test_ssl_certificate_chain_all_from_server); - SUITE_ADD_TEST(suite, test_ssl_no_servercert_callback_allok); - SUITE_ADD_TEST(suite, test_ssl_no_servercert_callback_fail); SUITE_ADD_TEST(suite, test_ssl_large_response); - SUITE_ADD_TEST(suite, test_ssl_large_request); - SUITE_ADD_TEST(suite, test_ssl_client_certificate); - SUITE_ADD_TEST(suite, test_ssl_expired_server_cert); - SUITE_ADD_TEST(suite, test_ssl_future_server_cert); - SUITE_ADD_TEST(suite, test_setup_ssltunnel); - SUITE_ADD_TEST(suite, test_ssltunnel_no_creds_cb); - SUITE_ADD_TEST(suite, test_ssltunnel_basic_auth); - SUITE_ADD_TEST(suite, test_ssltunnel_basic_auth_server_has_keepalive_off); - SUITE_ADD_TEST(suite, test_ssltunnel_basic_auth_proxy_has_keepalive_off); - SUITE_ADD_TEST(suite, test_ssltunnel_digest_auth); return suite; }