dllmain.c 2.2 KB

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