From: Jay Satiro Date: Wed, 13 Oct 2021 04:33:23 +0000 (-0400) Subject: sws: fix memory leak on exit X-Git-Tag: curl-7_80_0~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afd489885e0f497a6d4984638aace5904f71fa74;p=thirdparty%2Fcurl.git 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 --- diff --git a/tests/server/sws.c b/tests/server/sws.c index ee7975b605..6ce0d3b9fc 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -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");