sws: fix memory leak on exit

- Free the allocated http request struct on cleanup.

Prior to this change if sws was built with leak sanitizer it would
report a memory leak error during testing.

Closes https://github.com/curl/curl/pull/7849
This commit is contained in:
Jay Satiro 2021-10-13 00:33:23 -04:00
parent a3030b7db6
commit afd489885e

View file

@ -1878,7 +1878,7 @@ int main(int argc, char *argv[])
#endif
const char *pidname = ".http.pid";
const char *portname = ".http.port";
struct httprequest *req;
struct httprequest *req = NULL;
int rc = 0;
int error;
int arg = 1;
@ -1890,10 +1890,6 @@ int main(int argc, char *argv[])
/* a default CONNECT port is basically pointless but still ... */
size_t socket_idx;
req = calloc(1, sizeof(*req));
if(!req)
return 0;
while(argc>arg) {
if(!strcmp("--version", argv[arg])) {
puts("sws IPv4"
@ -2020,6 +2016,10 @@ int main(int argc, char *argv[])
install_signal_handlers(false);
req = calloc(1, sizeof(*req));
if(!req)
goto sws_cleanup;
sock = socket(socket_domain, SOCK_STREAM, 0);
all_sockets[0] = sock;
@ -2349,6 +2349,8 @@ sws_cleanup:
}
#endif
free(req);
if(got_exit_signal)
logmsg("signalled to die");