2
0

dllmain.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #ifdef USE_OPENSSL
  26. #include <openssl/crypto.h>
  27. #endif
  28. /* The fourth-to-last include */
  29. #ifdef __CYGWIN__
  30. #define WIN32_LEAN_AND_MEAN
  31. #include <windows.h>
  32. #ifdef _WIN32
  33. #undef _WIN32
  34. #endif
  35. #endif
  36. /* The last 3 #include files should be in this order */
  37. #include "curl_printf.h"
  38. #include "curl_memory.h"
  39. #include "memdebug.h"
  40. /* DllMain() must only be defined for Windows and Cygwin DLL builds. */
  41. #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(CURL_STATICLIB)
  42. #if defined(USE_OPENSSL) && \
  43. !defined(OPENSSL_IS_AWSLC) && \
  44. !defined(OPENSSL_IS_BORINGSSL) && \
  45. !defined(LIBRESSL_VERSION_NUMBER) && \
  46. (OPENSSL_VERSION_NUMBER >= 0x10100000L)
  47. #define PREVENT_OPENSSL_MEMLEAK
  48. #endif
  49. #ifdef PREVENT_OPENSSL_MEMLEAK
  50. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
  51. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  52. {
  53. (void)hinstDLL;
  54. (void)lpvReserved;
  55. switch(fdwReason) {
  56. case DLL_PROCESS_ATTACH:
  57. break;
  58. case DLL_PROCESS_DETACH:
  59. break;
  60. case DLL_THREAD_ATTACH:
  61. break;
  62. case DLL_THREAD_DETACH:
  63. /* Call OPENSSL_thread_stop to prevent a memory leak in case OpenSSL is
  64. linked statically.
  65. https://github.com/curl/curl/issues/12327#issuecomment-1826405944 */
  66. OPENSSL_thread_stop();
  67. break;
  68. }
  69. return TRUE;
  70. }
  71. #endif /* OpenSSL */
  72. #endif /* DLL build */