]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sws: fix memory leak on exit
authorJay Satiro <raysatiro@yahoo.com>
Wed, 13 Oct 2021 04:33:23 +0000 (00:33 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Thu, 14 Oct 2021 07:24:18 +0000 (03:24 -0400)
- 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

tests/server/sws.c

index ee7975b60575d1bcff46145bb3d9f7a9b3f99d5f..6ce0d3b9fcadcc46f5c63a92f0c4c5bd33697832 100644 (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");