/* * Deinitialize OpenSSL and free as much memory as possible. * Some 10k-100k will still remain resident no matter what. */ void ssl_fini(void) { if (!ssl_initialized) return; ERR_remove_state(0); /* current thread */ #ifdef OPENSSL_THREADS CRYPTO_set_locking_callback(NULL); CRYPTO_set_dynlock_create_callback(NULL); CRYPTO_set_dynlock_lock_callback(NULL); CRYPTO_set_dynlock_destroy_callback(NULL); #ifdef OPENSSL_NO_THREADID CRYPTO_set_id_callback(NULL); #else /* !OPENSSL_NO_THREADID */ CRYPTO_THREADID_set_callback(NULL); #endif /* !OPENSSL_NO_THREADID */ int i; for (i = 0; i < ssl_mutex_num; i++) { pthread_mutex_destroy(&ssl_mutex[i]); } free(ssl_mutex); #endif ENGINE_cleanup(); CONF_modules_finish(); CONF_modules_unload(1); CONF_modules_free(); EVP_cleanup(); ERR_free_strings(); CRYPTO_cleanup_all_ex_data(); }
// NOTE: we do not cleanup in reverse initialization order // the threading subsystem is deleted before the modules are // unloaded in case there are any module-specific thread // cleanup functions to be run... void qore_cleanup() { // first delete all user modules QMM.delUser(); #ifdef _Q_WINDOWS // do windows socket cleanup WSACleanup(); #endif #ifdef HAVE_SIGNAL_HANDLING // stop signal manager QSM.del(); #endif // purge thread resources before deleting modules { ExceptionSink xsink; purge_thread_resources(&xsink); } // delete all loadable modules QMM.cleanup(); // delete thread-local data delete_thread_local_data(); // now free memory (like ARGV, QORE_ARGV, ENV, etc) delete_global_variables(); // delete pseudo-methods pseudo_classes_del(); // delete static system namespace after modules delete staticSystemNamespace; #ifdef DEBUG staticSystemNamespace = 0; #endif // delete default type values delete_qore_types(); // delete threading infrastructure delete_qore_threads(); // only perform openssl cleanup if not performed externally if (!qore_check_option(QLO_DISABLE_OPENSSL_CLEANUP)) { // cleanup openssl library ERR_free_strings(); ENGINE_cleanup(); EVP_cleanup(); CONF_modules_finish(); CONF_modules_free(); CONF_modules_unload(1); CRYPTO_cleanup_all_ex_data(); CRYPTO_set_id_callback(0); CRYPTO_set_locking_callback(0); // delete openssl locks for (mutex_vec_t::iterator i = q_openssl_mutex_list.begin(), e = q_openssl_mutex_list.end(); i != e; ++i) delete *i; } printd(5, "qore_cleanup() exiting cleanly\n"); }