From e37e6f1bb89b7696208b3ab967926aa4ffa8ddfb Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 14 Dec 2022 18:19:20 +0000 Subject: [PATCH] Fix some memory bugs. --- man/man7/telodendria-changelog.7 | 8 +++++++- src/Http.c | 11 ++++++++--- src/HttpServer.c | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/man/man7/telodendria-changelog.7 b/man/man7/telodendria-changelog.7 index 26a4be8..a816663 100644 --- a/man/man7/telodendria-changelog.7 +++ b/man/man7/telodendria-changelog.7 @@ -38,12 +38,18 @@ homeserver changes and fixes: .Bl -bullet .It Fixed a memory leak that would occur when parsing an invalid -JSON object failed. +JSON object. .It Fixed an edge case where HTTP response headers were being sent before they were set properly, causing the server to report a status of 200 even when that wasn't the desired status. +.It +Fixed a few memory leaks in the HTTP parameter decoder that +would occur in some edge cases. +.It +Fixed an "off-by-one" error in the HTTP server that +prevented GET parameters from being parsed. .El .Pp Other changes and fixes included in this release: diff --git a/src/Http.c b/src/Http.c index 91f6d66..cc2ac9d 100644 --- a/src/Http.c +++ b/src/Http.c @@ -440,7 +440,7 @@ HttpParamDecode(char *in) if (!decKey) { /* Decoding error */ - Free(params); + HashMapFree(params); return NULL; } @@ -471,11 +471,16 @@ HttpParamDecode(char *in) if (!decVal) { /* Decoding error */ - Free(params); + HashMapFree(params); return NULL; } - HashMapSet(params, decKey, decVal); + buf = HashMapSet(params, decKey, decVal); + if (buf) + { + Free(buf); + Free(decKey); + } if (*in == '&') { diff --git a/src/HttpServer.c b/src/HttpServer.c index c819fe1..8a4965e 100644 --- a/src/HttpServer.c +++ b/src/HttpServer.c @@ -561,7 +561,7 @@ HttpServerWorkerThread(void *args) } requestPath[i] = '\0'; - requestParams = HttpParamDecode(requestPath + i); + requestParams = HttpParamDecode(requestPath + i + 1); context = HttpServerContextCreate(requestMethod, requestPath, requestParams, fp); if (!context)