-#ifdef OPENSSL_USE_NODELETE
- switch (test_type) {
- case JUST_CRYPTO:
- if (!TEST_true(shlib_close(cryptolib)))
- goto end;
- break;
- case CRYPTO_FIRST:
- if (!TEST_true(shlib_close(cryptolib))
- || !TEST_true(shlib_close(ssllib)))
+ myOPENSSL_atexit = (OPENSSL_atexit_t)symbols[2].func;
+ if (!myOPENSSL_atexit(atexit_handler)) {
+ fprintf(stderr, "Failed to register atexit handler\n");
+ goto end;
+ }
+
+ if (test_type == DSO_REFTEST) {
+# ifdef DSO_DLFCN
+ DSO_dsobyaddr_t myDSO_dsobyaddr;
+ DSO_free_t myDSO_free;
+
+ /*
+ * This is resembling the code used in ossl_init_base() and
+ * OPENSSL_atexit() to block unloading the library after dlclose().
+ * We are not testing this on Windows, because it is done there in a
+ * completely different way. Especially as a call to DSO_dsobyaddr()
+ * will always return an error, because DSO_pathbyaddr() is not
+ * implemented there.
+ */
+ if (!shlib_sym(cryptolib, "DSO_dsobyaddr", &symbols[0].sym)
+ || !shlib_sym(cryptolib, "DSO_free", &symbols[1].sym)) {
+ fprintf(stderr, "Unable to load DSO symbols\n");