static void ssl_library_stop(void) { /* Might be explicitly called and also by atexit */ if (stopped) return; stopped = 1; if (ssl_base_inited) { #ifndef OPENSSL_NO_COMP #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: ssl_library_stop: " "ssl_comp_free_compression_methods_int()\n"); #endif ssl_comp_free_compression_methods_int(); #endif } if (ssl_strings_inited) { #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: ssl_library_stop: " "err_free_strings_int()\n"); #endif /* * If both crypto and ssl error strings are inited we will end up * calling err_free_strings_int() twice - but that's ok. The second * time will be a no-op. It's easier to do that than to try and track * between the two libraries whether they have both been inited. */ err_free_strings_int(); } }
void OPENSSL_cleanup(void) { OPENSSL_INIT_STOP *currhandler, *lasthandler; /* If we've not been inited then no need to deinit */ if (!base_inited) return; /* Might be explicitly called and also by atexit */ if (stopped) return; stopped = 1; /* * Thread stop may not get automatically called by the thread library for * the very last thread in some situations, so call it directly. */ ossl_init_thread_stop(ossl_init_get_thread_local(0)); currhandler = stop_handlers; while (currhandler != NULL) { currhandler->handler(); lasthandler = currhandler; currhandler = currhandler->next; OPENSSL_free(lasthandler); } stop_handlers = NULL; CRYPTO_THREAD_lock_free(init_lock); /* * We assume we are single-threaded for this function, i.e. no race * conditions for the various "*_inited" vars below. */ #ifndef OPENSSL_NO_COMP if (zlib_inited) { #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "comp_zlib_cleanup_int()\n"); #endif comp_zlib_cleanup_int(); } #endif if (async_inited) { # ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "async_deinit()\n"); # endif async_deinit(); } if (load_crypto_strings_inited) { #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "err_free_strings_int()\n"); #endif err_free_strings_int(); } CRYPTO_THREAD_cleanup_local(&threadstopkey); #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "rand_cleanup_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "conf_modules_free_int()\n"); #ifndef OPENSSL_NO_ENGINE fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "engine_cleanup_int()\n"); #endif fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "crypto_cleanup_all_ex_data_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "bio_sock_cleanup_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "bio_cleanup()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "evp_cleanup_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "obj_cleanup_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "err_cleanup()\n"); #endif /* * Note that cleanup order is important: * - rand_cleanup_int could call an ENGINE's RAND cleanup function so * must be called before engine_cleanup_int() * - ENGINEs use CRYPTO_EX_DATA and therefore, must be cleaned up * before the ex data handlers are wiped in CRYPTO_cleanup_all_ex_data(). * - conf_modules_free_int() can end up in ENGINE code so must be called * before engine_cleanup_int() * - ENGINEs and additional EVP algorithms might use added OIDs names so * obj_cleanup_int() must be called last */ rand_cleanup_int(); conf_modules_free_int(); #ifndef OPENSSL_NO_ENGINE engine_cleanup_int(); #endif crypto_cleanup_all_ex_data_int(); bio_cleanup(); evp_cleanup_int(); obj_cleanup_int(); err_cleanup(); base_inited = 0; }