dllmain.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <[email protected]>, 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 last 3 #include files should be in this order */
  29. #include "curl_printf.h"
  30. #include "curl_memory.h"
  31. #include "memdebug.h"
  32. /* DllMain() must only be defined for Windows DLL builds. */
  33. #if defined(_WIN32) && !defined(CURL_STATICLIB)
  34. #if defined(USE_OPENSSL) && \
  35. !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC) && \
  36. !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  37. #define PREVENT_OPENSSL_MEMLEAK
  38. #endif
  39. #ifdef PREVENT_OPENSSL_MEMLEAK
  40. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
  41. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  42. {
  43. (void)hinstDLL;
  44. (void)lpvReserved;
  45. switch(fdwReason) {
  46. case DLL_PROCESS_ATTACH:
  47. break;
  48. case DLL_PROCESS_DETACH:
  49. break;
  50. case DLL_THREAD_ATTACH:
  51. break;
  52. case DLL_THREAD_DETACH:
  53. /* Call OPENSSL_thread_stop to prevent a memory leak in case OpenSSL is
  54. linked statically.
  55. https://github.com/curl/curl/issues/12327#issuecomment-1826405944 */
  56. OPENSSL_thread_stop();
  57. break;
  58. }
  59. return TRUE;
  60. }
  61. #endif /* OpenSSL */
  62. #endif /* DLL build */