Fix some memory bugs.

This commit is contained in:
Jordan Bancino 2022-12-14 18:19:20 +00:00
parent 5880cf3ea0
commit e37e6f1bb8
3 changed files with 16 additions and 5 deletions

View file

@ -38,12 +38,18 @@ homeserver changes and fixes:
.Bl -bullet .Bl -bullet
.It .It
Fixed a memory leak that would occur when parsing an invalid Fixed a memory leak that would occur when parsing an invalid
JSON object failed. JSON object.
.It .It
Fixed an edge case where HTTP response headers were being Fixed an edge case where HTTP response headers were being
sent before they were set properly, causing the server to sent before they were set properly, causing the server to
report a status of 200 even when that wasn't the desired report a status of 200 even when that wasn't the desired
status. 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 .El
.Pp .Pp
Other changes and fixes included in this release: Other changes and fixes included in this release:

View file

@ -440,7 +440,7 @@ HttpParamDecode(char *in)
if (!decKey) if (!decKey)
{ {
/* Decoding error */ /* Decoding error */
Free(params); HashMapFree(params);
return NULL; return NULL;
} }
@ -471,11 +471,16 @@ HttpParamDecode(char *in)
if (!decVal) if (!decVal)
{ {
/* Decoding error */ /* Decoding error */
Free(params); HashMapFree(params);
return NULL; return NULL;
} }
HashMapSet(params, decKey, decVal); buf = HashMapSet(params, decKey, decVal);
if (buf)
{
Free(buf);
Free(decKey);
}
if (*in == '&') if (*in == '&')
{ {

View file

@ -561,7 +561,7 @@ HttpServerWorkerThread(void *args)
} }
requestPath[i] = '\0'; requestPath[i] = '\0';
requestParams = HttpParamDecode(requestPath + i); requestParams = HttpParamDecode(requestPath + i + 1);
context = HttpServerContextCreate(requestMethod, requestPath, requestParams, fp); context = HttpServerContextCreate(requestMethod, requestPath, requestParams, fp);
if (!context) if (!context)