]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: add a destructor to free allocated SSL ressources
authorRemi Gacogne <rgacogne@aquaray.fr>
Thu, 28 May 2015 14:39:47 +0000 (16:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 May 2015 16:03:29 +0000 (18:03 +0200)
Using valgrind or another memory leak tracking tool is easier
when the memory internally allocated by OpenSSL is cleanly released
at shutdown.

src/ssl_sock.c

index a6717a3c7bdfdfe39ea3762e4fd617d26c46d4d6..e528db2aec2dd3e8a57ef5423d4dd4ffcd4d03de 100644 (file)
@@ -5060,6 +5060,42 @@ static void __ssl_sock_init(void)
 #endif
 }
 
+__attribute__((destructor))
+static void __ssl_sock_deinit(void)
+{
+#ifndef OPENSSL_NO_DH
+        if (local_dh_1024) {
+                DH_free(local_dh_1024);
+                local_dh_1024 = NULL;
+        }
+
+        if (local_dh_2048) {
+                DH_free(local_dh_2048);
+                local_dh_2048 = NULL;
+        }
+
+        if (local_dh_4096) {
+                DH_free(local_dh_4096);
+                local_dh_4096 = NULL;
+        }
+
+        if (local_dh_8192) {
+                DH_free(local_dh_8192);
+                local_dh_8192 = NULL;
+        }
+#endif
+
+        ERR_remove_state(0);
+        ERR_free_strings();
+
+        EVP_cleanup();
+
+#if OPENSSL_VERSION_NUMBER >= 0x00907000L
+        CRYPTO_cleanup_all_ex_data();
+#endif
+}
+
+
 /*
  * Local variables:
  *  c-indent-level: 8