From 7db9947fcf5d3deebe98e7992ebedc9a2f624bf5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 16 Jun 2026 13:50:51 +0200 Subject: [PATCH] servers: drop CRT and curlx calls from `main_window_loop()` (Windows) To simplify and to avoid the chance of potential interference or thread-safety issues. If one these 3 Win32 API calls fail, there is likely a serious problem, out of the code's control. Knowing `GetLastError()` is unlikely to help. Refs: https://learn.microsoft.com/windows/win32/api/winuser/nc-winuser-wndproc https://learn.microsoft.com/previous-versions/windows/desktop/legacy/ms686736(v=vs.85) https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-getmessage https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-createwindowexa https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-registerclassa Ref: 9ea48811fed455d4a869eb100b2216f039f8677a #22487 Ref: 1c49f2f26d0f200bb9de61f795f06a1bc56845e9 #18451 Follow-up to ac1e206278b98fbe762f4b554803c64e8b562156 Closes #22045 --- tests/server/util.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/server/util.c b/tests/server/util.c index ee8d401d5c..34d9a68587 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -471,7 +471,7 @@ static LRESULT CALLBACK main_window_proc(HWND hwnd, UINT uMsg, static const char msg[] = "main_window_proc(): WM_CLOSE -> SIGTERM\n"; DWORD dwWritten; WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, CURL_CSTRLEN(msg), - &dwWritten, NULL); + &dwWritten, NULL); exit_msg = msg; initiate_exit(SIGTERM); break; @@ -490,17 +490,16 @@ static DWORD WINAPI main_window_loop(void *lpParameter) WNDCLASS wc; BOOL ret; MSG msg; - DWORD err; - char buffer[WINAPI_ERROR_LEN]; + DWORD dwWritten; ZeroMemory(&wc, sizeof(wc)); wc.lpfnWndProc = (WNDPROC)main_window_proc; wc.hInstance = (HINSTANCE)lpParameter; wc.lpszClassName = TEXT("MainWClass"); if(!RegisterClass(&wc)) { - err = GetLastError(); - curlx_winapi_strerror(err, buffer, sizeof(buffer)); - fprintf(stderr, "RegisterClass failed: %s\n", buffer); + static const char str[] = "RegisterClass() failed\n"; + WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, CURL_CSTRLEN(str), + &dwWritten, NULL); return (DWORD)-1; } @@ -512,18 +511,18 @@ static DWORD WINAPI main_window_loop(void *lpParameter) (HWND)NULL, (HMENU)NULL, wc.hInstance, NULL); if(!hidden_main_window) { - err = GetLastError(); - curlx_winapi_strerror(err, buffer, sizeof(buffer)); - fprintf(stderr, "CreateWindowEx failed: (0x%08lx) - %s\n", err, buffer); + static const char str[] = "CreateWindowEx() failed\n"; + WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, CURL_CSTRLEN(str), + &dwWritten, NULL); return (DWORD)-1; } do { ret = GetMessage(&msg, NULL, 0, 0); if(ret == -1) { - err = GetLastError(); - curlx_winapi_strerror(err, buffer, sizeof(buffer)); - fprintf(stderr, "GetMessage failed: (0x%08lx) - %s\n", err, buffer); + static const char str[] = "GetMessage() failed\n"; + WriteFile(GetStdHandle(STD_ERROR_HANDLE), str, CURL_CSTRLEN(str), + &dwWritten, NULL); return (DWORD)-1; } else if(ret) {