← Commit list

fcde633450

Viktor Szakats
Viktor Szakats
2026-09-03
SUCCESS Duration: 418s

Subject

global_init: tidy up, simplify, fix issues

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

lib/Makefile.inc+0 -2
@@ -284,7 +284,6 @@ LIB_CFILES = \
strcase.c \
strequal.c \
strerror.c \
- system_win32.c \
telnet.c \
tftp.c \
thrdpool.c \
@@ -418,7 +417,6 @@ LIB_HFILES = \
splay.h \
strcase.h \
strerror.h \
- system_win32.h \
telnet.h \
tftp.h \
thrdpool.h \
lib/easy.c+52 -22
@@ -70,18 +70,20 @@
#include "vssh/ssh.h"
#include "setopt.h"
#include "http_digest.h"
-#include "system_win32.h"
#include "curlx/dynbuf.h"
#include "bufref.h"
#include "altsvc.h"
#include "hsts.h"
+#include "curl_sspi.h" /* Curl_sspi_global_init()/Curl_sspi_global_cleanup() */
+#include "curlx/timeval.h" /* for curlx_now_init() */
+#include "curlx/version_win32.h" /* for curlx_verify_windows_init() */
#include "easy_lock.h"
/* true globals -- for curl_global_init() and curl_global_cleanup() */
static unsigned int initialized;
-#ifdef _WIN32
-static long easy_init_flags;
+#ifdef USE_WINSOCK
+static bool winsock_initialized;
#endif
#ifdef GLOBAL_INIT_IS_THREADSAFE
@@ -126,6 +128,8 @@ static char *leakpointer;
*/
static CURLcode global_init(long flags, bool memoryfuncs)
{
+ (void)flags;
+
if(initialized++)
return CURLE_OK;
@@ -138,16 +142,40 @@ static CURLcode global_init(long flags, bool memoryfuncs)
Curl_ccalloc = (curl_calloc_callback)calloc;
}
- if(Curl_win32_init(flags)) {
- DEBUGF(curl_mfprintf(stderr, "Error: win32_init failed\n"));
- goto fail;
- }
+#ifdef _WIN32
+ curlx_verify_windows_init();
+ curlx_now_init();
+#endif
if(Curl_trc_init()) {
DEBUGF(curl_mfprintf(stderr, "Error: Curl_trc_init failed\n"));
goto fail;
}
+#ifdef USE_WINDOWS_SSPI
+ if(Curl_sspi_global_init()) {
+ DEBUGF(curl_mfprintf(stderr, "Error: Curl_sspi_global_init() failed\n"));
+ goto fail;
+ }
+#endif
+
+#ifdef _WIN32
+ /* CURL_GLOBAL_WIN32 controls the *optional* part of the initialization which
+ is for Winsock at the moment. */
+ if(flags & CURL_GLOBAL_WIN32) {
+#ifdef USE_WINSOCK
+ WSADATA wsa;
+ if(WSAStartup(MAKEWORD(2, 2), &wsa)) {
+ DEBUGF(curl_mfprintf(stderr, "Error: WSAStartup() failed\n"));
+ goto fail;
+ }
+ winsock_initialized = TRUE;
+#elif defined(USE_LWIPSOCK)
+ lwip_init();
+#endif
+ }
+#endif
+
if(!Curl_ssl_init()) {
DEBUGF(curl_mfprintf(stderr, "Error: Curl_ssl_init failed\n"));
goto fail;
@@ -178,12 +206,6 @@ static CURLcode global_init(long flags, bool memoryfuncs)
goto fail;
}
-#ifdef _WIN32
- easy_init_flags = flags;
-#else
- (void)flags;
-#endif
-
#ifdef DEBUGBUILD
if(getenv("CURL_GLOBAL_INIT"))
/* alloc data that will leak if *cleanup() is not called! */
@@ -193,6 +215,12 @@ static CURLcode global_init(long flags, bool memoryfuncs)
return CURLE_OK;
fail:
+#ifdef USE_WINSOCK
+ if(winsock_initialized) {
+ WSACleanup();
+ winsock_initialized = FALSE;
+ }
+#endif
initialized--; /* undo the increase */
return CURLE_FAILED_INIT;
}
@@ -255,9 +283,7 @@ CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
}
/**
- * curl_global_cleanup() globally cleanups curl, uses the value of
- * "easy_init_flags" to determine what needs to be cleaned up and what does
- * not.
+ * curl_global_cleanup() globally cleanups curl.
*/
void curl_global_cleanup(void)
{
@@ -273,18 +299,22 @@ void curl_global_cleanup(void)
return;
}
+ Curl_ssh_cleanup();
Curl_ssl_cleanup();
Curl_vquic_cleanup();
Curl_async_global_cleanup();
+ Curl_amiga_cleanup();
-#ifdef _WIN32
- Curl_win32_cleanup(easy_init_flags);
- easy_init_flags = 0;
+#ifdef USE_WINSOCK
+ if(winsock_initialized) {
+ WSACleanup();
+ winsock_initialized = FALSE;
+ }
#endif
- Curl_amiga_cleanup();
-
- Curl_ssh_cleanup();
+#ifdef USE_WINDOWS_SSPI
+ Curl_sspi_global_cleanup();
+#endif
#ifdef DEBUGBUILD
curlx_free(leakpointer);
lib/system_win32.c+0 -76
@@ -1,76 +0,0 @@
-/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
- * \___|\___/|_| \_\_____|
- *
- * Copyright (C) Steve Holme, <[email protected]>.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "curl_setup.h"
-
-#ifdef _WIN32
-
-#include "system_win32.h"
-#include "curl_sspi.h"
-#include "curlx/timeval.h"
-#include "curlx/version_win32.h" /* for curlx_verify_windows_init() */
-
-/* Curl_win32_init() performs Win32 global initialization */
-CURLcode Curl_win32_init(long flags)
-{
- /* CURL_GLOBAL_WIN32 controls the *optional* part of the initialization which
- is for Winsock at the moment. Any required Win32 initialization
- should take place after this block. */
- if(flags & CURL_GLOBAL_WIN32) {
-#ifdef USE_WINSOCK
- WSADATA wsa;
- if(WSAStartup(MAKEWORD(2, 2), &wsa))
- return CURLE_FAILED_INIT;
-#elif defined(USE_LWIPSOCK)
- lwip_init();
-#endif
- } /* CURL_GLOBAL_WIN32 */
-
-#ifdef USE_WINDOWS_SSPI
- {
- CURLcode result = Curl_sspi_global_init();
- if(result)
- return result;
- }
-#endif
-
- curlx_verify_windows_init();
- curlx_now_init();
- return CURLE_OK;
-}
-
-/* Curl_win32_cleanup() is the opposite of Curl_win32_init() */
-void Curl_win32_cleanup(long init_flags)
-{
-#ifdef USE_WINDOWS_SSPI
- Curl_sspi_global_cleanup();
-#endif
-
- if(init_flags & CURL_GLOBAL_WIN32) {
-#ifdef USE_WINSOCK
- WSACleanup();
-#endif
- }
-}
-
-#endif /* _WIN32 */
lib/system_win32.h+0 -35
@@ -1,35 +0,0 @@
-#ifndef HEADER_CURL_SYSTEM_WIN32_H
-#define HEADER_CURL_SYSTEM_WIN32_H
-/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
- * \___|\___/|_| \_\_____|
- *
- * Copyright (C) Steve Holme, <[email protected]>.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "curl_setup.h"
-
-#ifdef _WIN32
-CURLcode Curl_win32_init(long flags);
-void Curl_win32_cleanup(long init_flags);
-#else
-#define Curl_win32_init(x) CURLE_OK
-#endif /* _WIN32 */
-
-#endif /* HEADER_CURL_SYSTEM_WIN32_H */