summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2021-10-13 00:33:23 -0400
committerJay Satiro <raysatiro@yahoo.com>2021-10-14 03:24:18 -0400
commitafd489885e0f497a6d4984638aace5904f71fa74 (patch)
treec913e93654718cc400db0cc9a1227b6a8bcadfb3
parenta3030b7db6b1cf491287c0ccfac67605646883e2 (diff)
downloadcurl-afd489885e0f497a6d4984638aace5904f71fa74.tar.gz
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
-rw-r--r--tests/server/sws.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/tests/server/sws.c b/tests/server/sws.c
index ee7975b60..6ce0d3b9f 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");