| Hmm, the final patch is a bit more clean.
--- /tmp/htsmodules.c.orig 2006-08-05 09:13:26.529328409 +0200
+++ /tmp/htsmodules.c 2006-08-05 09:10:26.000000000 +0200
@@ -238,36 +238,17 @@
return NULL;
}
+void* ssl_handle = NULL;
+#ifdef _WIN32
+void* ssl_handle_2 = NULL;
+#endif
void htspe_init() {
static int initOk = 0;
@@ -293,6 +274,7 @@
handle = dlopen("libssl.so.0", RTLD_LAZY);
}
#endif
+ ssl_handle = handle;
if (handle) {
SSL_shutdown = (t_SSL_shutdown) DynamicGet(handle,
(char*)"SSL_shutdown");
SSL_free = (t_SSL_free) DynamicGet(handle, (char*)"SSL_free");
@@ -312,6 +294,7 @@
SSL_CTX_ctrl = (t_SSL_CTX_ctrl) DynamicGet(handle,
(char*)"SSL_CTX_ctrl");
#ifdef _WIN32
handle = LoadLibraryA((char*)"libeay32");
+ ssl_handle_2 = handle;
#endif
ERR_load_crypto_strings = (t_ERR_load_crypto_strings)
DynamicGet(handle, (char*)"ERR_load_crypto_strings");
ERR_error_string = (t_ERR_error_string) DynamicGet(handle,
(char*)"ERR_error_string");
@@ -332,11 +315,21 @@
V6_is_available ? "" : "-noV6",
gz_is_available ? "" : "-nozip",
SSL_is_available ? "" : "-nossl");
-
-
}
}
+void htspe_uninit() {
+#ifdef _WIN32
+ CloseHandle(ssl_handle);
+ CloseHandle(ssl_handle_2);
+ ssl_handle = NULL;
+ ssl_handle_2 = NULL;
+#else
+ dlclose(ssl_handle);
+ ssl_handle = NULL;
+#endif
+}
+
static void htspe_log(htsmoduleStruct* str, const char* msg) {
const char* savename = str->filename;
httrackp* opt = (httrackp*) str->opt;
--- /tmp/htslib.c.orig 2006-08-05 09:13:26.537327635 +0200
+++ /tmp/htslib.c 2006-08-05 09:09:40.000000000 +0200
@@ -4990,12 +4990,12 @@
#endif
#endif
- /* Init threads */
+ /* Init threads (lazy init) */
htsthread_init();
/* Ensure external modules are loaded */
HTS_DBG("calling htspe_init()"); /* debug */
- htspe_init(); /* module load */
+ htspe_init(); /* module load (lazy) */
/* MD5 Auto-test */
{
@@ -5034,9 +5034,17 @@
return 1;
}
+/* will not free thread env. */
HTSEXT_API int hts_uninit() {
+ /* hts_init() is a lazy initializer, with limited a allocation (one or two
mutexes) ;
+ we won't free anything here as the .h semantic was never being very clear
*/
+}
+
+HTSEXT_API int hts_uninit_module() {
if (!hts_init_ok)
return 1;
+ htsthread_uninit();
+ htspe_uninit();
hts_init_ok = 0;
return 1;
}
--- /tmp/htsmodules.h.orig 2006-08-05 09:13:26.541327247 +0200
+++ /tmp/htsmodules.h 2006-08-05 09:08:08.000000000 +0200
@@ -134,6 +134,7 @@
HTSEXT_API const char* hts_get_version_info(httrackp *opt);
HTSEXT_API const char* hts_is_available(void);
extern void htspe_init(void);
+extern void htspe_uninit(void);
extern int hts_parse_externals(htsmoduleStruct* str);
extern int gz_is_available;
--- /tmp/htsthread.c.orig 2006-08-05 09:13:26.545326860 +0200
+++ /tmp/htsthread.c 2006-08-05 09:02:17.000000000 +0200
@@ -48,7 +48,7 @@
#endif
static int process_chain = 0;
-static htsmutex process_chain_mutex;
+static htsmutex process_chain_mutex = HTSMUTEX_INIT;
HTSEXT_API void htsthread_wait(void ) {
htsthread_wait_n(0);
@@ -67,10 +67,15 @@
#endif
}
+/* ensure initialized */
HTSEXT_API void htsthread_init(void ) {
#if USE_BEGINTHREAD
+#if (defined(_DEBUG) || defined(DEBUG))
assertf(process_chain == 0);
+#endif
+ if (process_chain_mutex == HTSMUTEX_INIT) {
hts_mutexinit(&process_chain_mutex);
+ }
#endif
}
| |