From 83748b320779c891c8dbef6720acfa6f6f3f39a7 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 3 Jan 2024 11:01:32 +0200 Subject: [server,browser-cli] Fixed memory leaks --- browser-cli.c | 4 +++- server.c | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/browser-cli.c b/browser-cli.c index d3d4c2f..3bea4ba 100644 --- a/browser-cli.c +++ b/browser-cli.c @@ -140,7 +140,9 @@ int handleCLI(sds *host, sds *port, sds *uri, const sds page) { // Handle relative URLs if (startPath == newURI) { - newURI = sdscatsds(sdsnewlen(*uri, findBeginningOfPath(*uri) - *uri), newURI); + sds beforePath = sdscatsds(sdsnewlen(*uri, findBeginningOfPath(*uri) - *uri), newURI); + sdsfree(newURI); + newURI = beforePath; startPath = findBeginningOfPath(newURI); } diff --git a/server.c b/server.c index dab19b4..5e9074e 100644 --- a/server.c +++ b/server.c @@ -102,7 +102,8 @@ int main(int argc, char* argv[]) { close(fd_socket); handleCLI(vhosts, vhostsc); freeVhosts(vhosts, vhostsc); - //while(wait(NULL) > 0); + sdsfree(host); + sdsfree(port); return 0; } @@ -169,6 +170,8 @@ int main(int argc, char* argv[]) { on_connection(strAddr, fd_client, vhosts, argc - 1); close(fd_client); freeVhosts(vhosts, vhostsc); + sdsfree(host); + sdsfree(port); return 0; } close(fd_client); @@ -177,4 +180,6 @@ int main(int argc, char* argv[]) { while(wait(NULL) > 0); freeVhosts(vhosts, vhostsc); close(fd_socket); + sdsfree(host); + sdsfree(port); } -- cgit v1.2.3