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