You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. From 269a02fbb332da8faf6c2a614d45d5b5018816d1 Mon Sep 17 00:00:00 2001
  2. From: Remi Gacogne <rgacogne@aquaray.fr>
  3. Date: Thu, 28 May 2015 16:39:47 +0200
  4. Subject: [PATCH 11/14] MINOR: ssl: add a destructor to free allocated SSL
  5. ressources
  6. Using valgrind or another memory leak tracking tool is easier
  7. when the memory internally allocated by OpenSSL is cleanly released
  8. at shutdown.
  9. (cherry picked from commit d3a23c3eb8c0950d26204568a133207099923494)
  10. ---
  11. src/ssl_sock.c | 36 ++++++++++++++++++++++++++++++++++++
  12. 1 file changed, 36 insertions(+)
  13. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  14. index d0f4d01..a78fc6a 100644
  15. --- a/src/ssl_sock.c
  16. +++ b/src/ssl_sock.c
  17. @@ -4717,6 +4717,42 @@ static void __ssl_sock_init(void)
  18. cfg_register_keywords(&cfg_kws);
  19. }
  20. +__attribute__((destructor))
  21. +static void __ssl_sock_deinit(void)
  22. +{
  23. +#ifndef OPENSSL_NO_DH
  24. + if (local_dh_1024) {
  25. + DH_free(local_dh_1024);
  26. + local_dh_1024 = NULL;
  27. + }
  28. +
  29. + if (local_dh_2048) {
  30. + DH_free(local_dh_2048);
  31. + local_dh_2048 = NULL;
  32. + }
  33. +
  34. + if (local_dh_4096) {
  35. + DH_free(local_dh_4096);
  36. + local_dh_4096 = NULL;
  37. + }
  38. +
  39. + if (local_dh_8192) {
  40. + DH_free(local_dh_8192);
  41. + local_dh_8192 = NULL;
  42. + }
  43. +#endif
  44. +
  45. + ERR_remove_state(0);
  46. + ERR_free_strings();
  47. +
  48. + EVP_cleanup();
  49. +
  50. +#if OPENSSL_VERSION_NUMBER >= 0x00907000L
  51. + CRYPTO_cleanup_all_ex_data();
  52. +#endif
  53. +}
  54. +
  55. +
  56. /*
  57. * Local variables:
  58. * c-indent-level: 8
  59. --
  60. 2.0.5