forked from lda/telodendria
Fix memory leaks in hdoc.
This commit is contained in:
parent
ff0a9f33b8
commit
f2f972bb9d
10 changed files with 36 additions and 16 deletions
|
@ -417,6 +417,7 @@ HeaderParse(Stream * stream, HeaderExpr * expr)
|
||||||
StrEquals(word, "endif"))
|
StrEquals(word, "endif"))
|
||||||
{
|
{
|
||||||
/* Read no more words, that's the whole directive */
|
/* Read no more words, that's the whole directive */
|
||||||
|
Free(word);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,7 +98,7 @@ main(int argc, char **argv)
|
||||||
envp = environ;
|
envp = environ;
|
||||||
while (*envp)
|
while (*envp)
|
||||||
{
|
{
|
||||||
size_t valInd;
|
size_t valInd;
|
||||||
|
|
||||||
/* It is unclear whether or not envp strings are writable, so
|
/* It is unclear whether or not envp strings are writable, so
|
||||||
* we make our own copy to manipulate it */
|
* we make our own copy to manipulate it */
|
||||||
|
@ -109,7 +109,7 @@ main(int argc, char **argv)
|
||||||
val = key + valInd + 1;
|
val = key + valInd + 1;
|
||||||
HashMapSet(args.env, key, StrDuplicate(val));
|
HashMapSet(args.env, key, StrDuplicate(val));
|
||||||
Free(key);
|
Free(key);
|
||||||
envp++;
|
envp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_create(&mainThread, NULL, MainThread, &args) != 0)
|
if (pthread_create(&mainThread, NULL, MainThread, &args) != 0)
|
||||||
|
@ -146,7 +146,7 @@ finish:
|
||||||
HashMapFree(args.env);
|
HashMapFree(args.env);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LOG_DEBUG, "Exitting with code: %d", ret);
|
Log(LOG_DEBUG, "Exitting with code: %d", ret);
|
||||||
|
|
||||||
LogConfigFree(LogConfigGlobal());
|
LogConfigFree(LogConfigGlobal());
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ finish:
|
||||||
StreamClose(StreamStdin());
|
StreamClose(StreamStdin());
|
||||||
StreamClose(StreamStderr());
|
StreamClose(StreamStderr());
|
||||||
|
|
||||||
GenerateMemoryReport(argv[0]);
|
GenerateMemoryReport(argc, argv);
|
||||||
|
|
||||||
MemoryFreeAll();
|
MemoryFreeAll();
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ MemoryIterator(MemoryInfo * i, void *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GenerateMemoryReport(const char *prog)
|
GenerateMemoryReport(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char reportName[128];
|
char reportName[128];
|
||||||
char *namePtr;
|
char *namePtr;
|
||||||
|
@ -77,6 +77,7 @@ GenerateMemoryReport(const char *prog)
|
||||||
time_t currentTime;
|
time_t currentTime;
|
||||||
struct tm *timeInfo;
|
struct tm *timeInfo;
|
||||||
char tsBuffer[1024];
|
char tsBuffer[1024];
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if (!MemoryAllocated())
|
if (!MemoryAllocated())
|
||||||
{
|
{
|
||||||
|
@ -86,7 +87,7 @@ GenerateMemoryReport(const char *prog)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(reportName, sizeof(reportName), "%s-leaked.txt", prog);
|
snprintf(reportName, sizeof(reportName), "%s-leaked.txt", argv[0]);
|
||||||
/* Make sure the report goes in the current working directory. */
|
/* Make sure the report goes in the current working directory. */
|
||||||
namePtr = basename(reportName);
|
namePtr = basename(reportName);
|
||||||
report = fopen(namePtr, "a");
|
report = fopen(namePtr, "a");
|
||||||
|
@ -100,8 +101,12 @@ GenerateMemoryReport(const char *prog)
|
||||||
strftime(tsBuffer, sizeof(tsBuffer), "%c", timeInfo);
|
strftime(tsBuffer, sizeof(tsBuffer), "%c", timeInfo);
|
||||||
|
|
||||||
fprintf(report, "---------- Memory Report ----------\n");
|
fprintf(report, "---------- Memory Report ----------\n");
|
||||||
fprintf(report, "Program: %s\n", prog);
|
fprintf(report, "Program:");
|
||||||
fprintf(report, "Date: %s\n", tsBuffer);
|
for (i = 0; i < argc; i++)
|
||||||
|
{
|
||||||
|
fprintf(report, " '%s'", argv[i]);
|
||||||
|
}
|
||||||
|
fprintf(report, "\nDate: %s\n", tsBuffer);
|
||||||
fprintf(report, "Total Bytes: %lu\n", MemoryAllocated());
|
fprintf(report, "Total Bytes: %lu\n", MemoryAllocated());
|
||||||
fprintf(report, "\n");
|
fprintf(report, "\n");
|
||||||
|
|
||||||
|
|
|
@ -41,13 +41,13 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a memory report to a file in the current directory, using
|
* Write a memory report to a file in the current directory, using
|
||||||
* the provided string as the name of the program currently being
|
* the provided program arguments, including the program name that
|
||||||
* executed. This function is to be called after all memory is
|
* executed. This function is to be called after all memory is
|
||||||
* supposed to have been freed. It iterates over all remaining
|
* supposed to have been freed. It iterates over all remaining
|
||||||
* memory and generates a text file containing all of the
|
* memory and generates a text file containing all of the
|
||||||
* recorded information about each block, including a hex dump of
|
* recorded information about each block, including a hex dump of
|
||||||
* the data stored in them.
|
* the data stored in them.
|
||||||
*/
|
*/
|
||||||
extern void GenerateMemoryReport(const char *);
|
extern void GenerateMemoryReport(int argc, char **argv);
|
||||||
|
|
||||||
#endif /* CYTOPLASM_RUNTIME_H */
|
#endif /* CYTOPLASM_RUNTIME_H */
|
||||||
|
|
|
@ -527,23 +527,35 @@ finish:
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(declarations); i++)
|
for (i = 0; i < ArraySize(declarations); i++)
|
||||||
{
|
{
|
||||||
Free(ArrayGet(declarations, i));
|
size_t j;
|
||||||
|
|
||||||
|
decl = ArrayGet(declarations, i);
|
||||||
|
for (j = 0; j < ArraySize(decl->decl.args); j++)
|
||||||
|
{
|
||||||
|
Free(ArrayGet(decl->decl.args, j));
|
||||||
|
}
|
||||||
|
ArrayFree(decl->decl.args);
|
||||||
|
Free(decl);
|
||||||
}
|
}
|
||||||
|
ArrayFree(declarations);
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(typedefs); i++)
|
for (i = 0; i < ArraySize(typedefs); i++)
|
||||||
{
|
{
|
||||||
Free(ArrayGet(typedefs, i));
|
Free(ArrayGet(typedefs, i));
|
||||||
}
|
}
|
||||||
|
ArrayFree(typedefs);
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(globals); i++)
|
for (i = 0; i < ArraySize(globals); i++)
|
||||||
{
|
{
|
||||||
Free(ArrayGet(globals, i));
|
Free(ArrayGet(globals, i));
|
||||||
}
|
}
|
||||||
|
ArrayFree(globals);
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(descr); i++)
|
for (i = 0; i < ArraySize(descr); i++)
|
||||||
{
|
{
|
||||||
Free(ArrayGet(descr, i));
|
Free(ArrayGet(descr, i));
|
||||||
}
|
}
|
||||||
|
ArrayFree(descr);
|
||||||
|
|
||||||
while (HashMapIterate(registers, &key, (void **) &val))
|
while (HashMapIterate(registers, &key, (void **) &val))
|
||||||
{
|
{
|
||||||
|
|
2
TODO.txt
2
TODO.txt
|
@ -24,7 +24,7 @@ Milestone: v0.3.0
|
||||||
[ ] Debug OpenSSL
|
[ ] Debug OpenSSL
|
||||||
[ ] Documentation
|
[ ] Documentation
|
||||||
[ ] hdoc(1) and hdoc(5)
|
[ ] hdoc(1) and hdoc(5)
|
||||||
[ ] Fix memory leaks in hdoc
|
[x] Fix memory leaks in hdoc
|
||||||
|
|
||||||
Milestone: v0.4.0
|
Milestone: v0.4.0
|
||||||
-----------------
|
-----------------
|
||||||
|
|
|
@ -91,7 +91,7 @@ typedef enum ArgFlag
|
||||||
} ArgFlag;
|
} ArgFlag;
|
||||||
|
|
||||||
int
|
int
|
||||||
Main(Array *args)
|
Main(Array * args)
|
||||||
{
|
{
|
||||||
int exit;
|
int exit;
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,9 @@ recipe_docs() {
|
||||||
recipe_cytoplasm() {
|
recipe_cytoplasm() {
|
||||||
cd Cytoplasm
|
cd Cytoplasm
|
||||||
export TLS_IMPL
|
export TLS_IMPL
|
||||||
sh make.sh
|
if ! sh make.sh; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
CYTOPLASM_FLAGS="Cytoplasm/out/lib/cytoplasm.o -LCytoplasm/out/lib -lcytoplasm $(sh make.sh libs)"
|
CYTOPLASM_FLAGS="Cytoplasm/out/lib/cytoplasm.o -LCytoplasm/out/lib -lcytoplasm $(sh make.sh libs)"
|
||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ usage(char *prog)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Main(Array *args)
|
Main(Array * args)
|
||||||
{
|
{
|
||||||
HttpClientContext *cx;
|
HttpClientContext *cx;
|
||||||
HttpStatus res;
|
HttpStatus res;
|
||||||
|
|
|
@ -178,7 +178,7 @@ encode(char *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Main(Array *args)
|
Main(Array * args)
|
||||||
{
|
{
|
||||||
HashMap *json;
|
HashMap *json;
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
|
|
Loading…
Reference in a new issue