mirror of
https://github.com/curl/curl.git
synced 2026-07-24 16:47:16 +03:00
tidy-up: prefer return over exit(), fix fallouts
To avoid breaking the control flow and align to majority of code
already using `return`.
`exit()` has the side-effect of suppressing leak detection in cases.
Fix fallouts detected after switching to `return`.
- configure:
- fix `getaddrinfo` run test to call `freeaddrinfo()` to pacify ASAN,
and call `WSACleanup()` to deinit winsock2.
- fix `getifaddrs` run test to call `freeifaddrs()` to pacify ASAN.
- tests/server:
- setup `atexit(win32_cleanup)` via `win32_init()`.
- return 2 instead of 1 on winsock2 init failures.
- sws: goto cleanup instead of `exit()` in `http_connect()`.
Follow-up to 02dfe71937 #7235
- tests/client/http:
- cleanup memory to pacify ASAN in `h2-upgrade-extreme`,
`tls-session-reuse`.
- examples:
- block_ip: fix memory leak reported by CI.
- http2-upload: avoid handle leaks.
Untouched `exit()` calls, made from callbacks:
- docs/examples: ephiperfifo.c, ghiper.c, hiperfifo.c
- tests/libtest: lib582.c, lib655.c, lib670.c
- tests/server: tftpd.c
Closes #16507
This commit is contained in:
parent
2e585f5640
commit
08c7c937dc
22 changed files with 222 additions and 150 deletions
|
|
@ -1018,8 +1018,8 @@ int main(int argc, char *argv[])
|
|||
logdir, SERVERLOGS_LOCKDIR, ipv_inuse);
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
CURL_SET_BINMODE(stdin);
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
#if defined(CURLRES_IPV6)
|
||||
|
|
|
|||
|
|
@ -1145,8 +1145,8 @@ int main(int argc, char *argv[])
|
|||
logdir, SERVERLOGS_LOCKDIR, ipv_inuse);
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
install_signal_handlers(false);
|
||||
|
|
|
|||
|
|
@ -1507,8 +1507,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
CURL_SET_BINMODE(stdin);
|
||||
|
|
|
|||
|
|
@ -1086,8 +1086,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
CURL_SET_BINMODE(stdin);
|
||||
|
|
|
|||
|
|
@ -1611,7 +1611,7 @@ static void http_connect(curl_socket_t *infdp,
|
|||
if(!req2) {
|
||||
req2 = malloc(sizeof(*req2));
|
||||
if(!req2)
|
||||
exit(1);
|
||||
goto http_connect_cleanup; /* fail */
|
||||
}
|
||||
memset(req2, 0, sizeof(*req2));
|
||||
logmsg("====> Client connect DATA");
|
||||
|
|
@ -2207,8 +2207,8 @@ int main(int argc, char *argv[])
|
|||
is_proxy ? "-proxy" : "", socket_type);
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
install_signal_handlers(false);
|
||||
|
|
|
|||
|
|
@ -644,8 +644,8 @@ int main(int argc, char **argv)
|
|||
logdir, SERVERLOGS_LOCKDIR, ipv_inuse);
|
||||
|
||||
#ifdef _WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
if(win32_init())
|
||||
return 2;
|
||||
#endif
|
||||
|
||||
install_signal_handlers(true);
|
||||
|
|
|
|||
|
|
@ -153,7 +153,17 @@ void win32_perror(const char *msg)
|
|||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
|
||||
void win32_init(void)
|
||||
static void win32_cleanup(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
WSACleanup();
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
/* flush buffers of all streams regardless of their mode */
|
||||
_flushall();
|
||||
}
|
||||
|
||||
int win32_init(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
WORD wVersionRequested;
|
||||
|
|
@ -166,7 +176,7 @@ void win32_init(void)
|
|||
if(err) {
|
||||
perror("Winsock init failed");
|
||||
logmsg("Error initialising Winsock -- aborting");
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
|
||||
|
|
@ -174,19 +184,11 @@ void win32_init(void)
|
|||
WSACleanup();
|
||||
perror("Winsock init failed");
|
||||
logmsg("No suitable winsock.dll found -- aborting");
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
#endif /* USE_WINSOCK */
|
||||
}
|
||||
|
||||
void win32_cleanup(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
WSACleanup();
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
/* flush buffers of all streams regardless of their mode */
|
||||
_flushall();
|
||||
atexit(win32_cleanup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* socket-safe strerror (works on Winsock errors, too) */
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@ extern const char *cmdfile;
|
|||
#define perror(m) win32_perror(m)
|
||||
void win32_perror(const char *msg);
|
||||
|
||||
void win32_init(void);
|
||||
void win32_cleanup(void);
|
||||
int win32_init(void);
|
||||
const char *sstrerror(int err);
|
||||
#else /* _WIN32 */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue