Quellcode durchsuchen

* Cleanup symbol tables when unloading

Bryan Drewery vor 15 Jahren
Ursprung
Commit
93abfccba6
3 geänderte Dateien mit 17 neuen und 0 gelöschten Zeilen
  1. 1 0
      src/dl.h
  2. 8 0
      src/libcrypto.c
  3. 8 0
      src/libssl.c

+ 1 - 0
src/dl.h

@@ -20,6 +20,7 @@
 #define DLSYM_GLOBAL(_handle, x) do { \
   dlerror(); \
   dl_symbol_table[#x] = (FunctionPtr) ((x##_t) dlsym(_handle, #x)); \
+  my_symbols << #x; \
   dlsym_error = dlerror(); \
   if (dlsym_error) { \
     sdprintf("%s", dlsym_error); \

+ 8 - 0
src/libcrypto.c

@@ -34,6 +34,7 @@
 #include "libcrypto.h"
 
 void *libcrypto_handle = NULL;
+static bd::Array<bd::String> my_symbols;
 
 static int load_symbols(void *handle) {
   const char *dlsym_error = NULL;
@@ -97,6 +98,13 @@ int load_libcrypto() {
 
 int unload_libcrypto() {
   if (libcrypto_handle) {
+    // Cleanup symbol table
+    for (size_t i = 0; i < my_symbols.length(); ++i) {
+      dl_symbol_table.remove(my_symbols[i]);
+      static_cast<bd::String>(my_symbols[i]).clear();
+    }
+    my_symbols.clear();
+
     dlclose(libcrypto_handle);
     libcrypto_handle = NULL;
     return 0;

+ 8 - 0
src/libssl.c

@@ -34,6 +34,7 @@
 #include "libssl.h"
 
 void *libssl_handle = NULL;
+static bd::Array<bd::String> my_symbols;
 #ifdef EGG_SSL_EXT
 SSL_CTX *ssl_ctx = NULL;
 char	*tls_rand_file = NULL;
@@ -119,6 +120,13 @@ int unload_ssl() {
       RAND_write_file(tls_rand_file);
 #endif
 
+    // Cleanup symbol table
+    for (size_t i = 0; i < my_symbols.length(); ++i) {
+      dl_symbol_table.remove(my_symbols[i]);
+      static_cast<bd::String>(my_symbols[i]).clear();
+    }
+    my_symbols.clear();
+
     dlclose(libssl_handle);
     libssl_handle = NULL;
     return 0;