Fix some sneaky memory bugs and resource leaks.

This commit is contained in:
Jordan Bancino 2022-11-01 09:04:15 -04:00
parent bf65f29fdf
commit 82d460da6f
3 changed files with 21 additions and 4 deletions

View file

@ -165,7 +165,9 @@ HttpServerContextFree(HttpServerContext * c)
HashMapFree(c->requestParams);
Free(c->requestPath);
#if 0
fclose(c->stream);
#endif
Free(c);
}
@ -513,7 +515,7 @@ HttpServerWorkerThread(void *args)
}
requestPath[i] = '\0';
requestParams = HttpParamDecode(requestPath + i + 1);
requestParams = HttpParamDecode(requestPath + i);
context = HttpServerContextCreate(requestMethod, requestPath, requestParams, fp);
if (!context)
@ -596,7 +598,9 @@ bad_request:
finish:
Free(line);
#if 0
fclose(fp);
#endif
}
return NULL;

View file

@ -334,12 +334,13 @@ MemoryInfoGet(void *p)
}
else
{
break;
pthread_mutex_unlock(&lock);
return allocations[hash];
}
}
pthread_mutex_unlock(&lock);
return allocations[hash];
return NULL;
}
size_t

View file

@ -154,7 +154,6 @@ main(int argc, char **argv)
memset(&matrixArgs, 0, sizeof(matrixArgs));
lc = LogConfigCreate();
LogConfigLevelSet(lc, LOG_DEBUG);
if (!lc)
{
@ -212,6 +211,7 @@ main(int argc, char **argv)
}
else
{
fclose(stdin);
#ifdef __OpenBSD__
if (unveil(configArg, "r") != 0)
{
@ -472,6 +472,16 @@ finish:
HttpServerFree(httpServer);
Log(lc, LOG_DEBUG, "Freed HTTP Server.");
}
/*
* If we're not logging to standard output, then we can close it. Otherwise,
* if we are logging to stdout, LogConfigFree() will close it for us.
*/
if (!(tConfig->flags & TELODENDRIA_LOG_STDOUT))
{
fclose(stdout);
}
TelodendriaConfigFree(tConfig);
DbClose(matrixArgs.db);
@ -483,5 +493,7 @@ finish:
LogConfigFree(lc);
MemoryFreeAll();
fclose(stderr);
return exit;
}