mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
Fix memory leaks
This commit is contained in:
parent
59e81eeb7f
commit
fcc57a1185
3 changed files with 8 additions and 18 deletions
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ PREFIX := /usr/local
|
|||
BINDIR := $(PREFIX)/bin
|
||||
|
||||
CC ?= clang
|
||||
CFLAGS += -Wall -I. -fomit-frame-pointer -fno-stack-protector -fno-common
|
||||
CFLAGS += -Wall -I. -Os
|
||||
#turn on tons of warnings if clang is present
|
||||
ifeq ($(CC), clang)
|
||||
CFLAGS += \
|
||||
|
|
15
test.c
15
test.c
|
@ -571,8 +571,8 @@ void task_template_destroy(task_template_t **template) {
|
|||
* checks will fail if template pointer is reused.
|
||||
*/
|
||||
mem_d(*template);
|
||||
task_template_nullify(*template);
|
||||
*template = NULL;
|
||||
//task_template_nullify(*template);
|
||||
//*template = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -861,6 +861,8 @@ bool task_execute(task_template_t *template) {
|
|||
*/
|
||||
success = !!!(strcmp(data, template->comparematch[compare++]));
|
||||
}
|
||||
mem_d(data);
|
||||
data = NULL;
|
||||
}
|
||||
pclose(execute);
|
||||
return success;
|
||||
|
@ -874,7 +876,6 @@ bool task_execute(task_template_t *template) {
|
|||
*/
|
||||
void task_schedualize(const char *curdir) {
|
||||
bool execute = false;
|
||||
char *back = NULL;
|
||||
char *data = NULL;
|
||||
size_t size = 0;
|
||||
size_t i;
|
||||
|
@ -898,12 +899,10 @@ void task_schedualize(const char *curdir) {
|
|||
* then we do the same for stderr.
|
||||
*/
|
||||
while (util_getline(&data, &size, task_tasks[i].runhandles[1]) != EOF) {
|
||||
back = data;
|
||||
fputs(data, task_tasks[i].stdoutlog);
|
||||
fflush(task_tasks[i].stdoutlog);
|
||||
}
|
||||
while (util_getline(&data, &size, task_tasks[i].runhandles[2]) != EOF) {
|
||||
back = data;
|
||||
/*
|
||||
* If a string contains an error we just dissalow execution
|
||||
* of it in the vm.
|
||||
|
@ -920,9 +919,8 @@ void task_schedualize(const char *curdir) {
|
|||
fputs(data, task_tasks[i].stderrlog);
|
||||
fflush(task_tasks[i].stdoutlog);
|
||||
}
|
||||
//mem_d(data);
|
||||
|
||||
if (back)
|
||||
mem_d(back);
|
||||
|
||||
/*
|
||||
* If we can execute we do so after all data has been read and
|
||||
|
@ -952,8 +950,7 @@ void task_schedualize(const char *curdir) {
|
|||
task_tasks[i].template->successmessage : "unknown"
|
||||
);
|
||||
}
|
||||
if (back)
|
||||
mem_d(back);
|
||||
mem_d(data);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
9
util.c
9
util.c
|
@ -450,16 +450,9 @@ int util_getline(char **lineptr, size_t *n, FILE *stream) {
|
|||
int c = getc(stream);
|
||||
|
||||
if (chr < 2) {
|
||||
char *tmp = (char*)mem_a((*n+=(*n>16)?*n:64));
|
||||
if (!tmp)
|
||||
return -1;
|
||||
|
||||
memcpy(tmp, *lineptr, pos - *lineptr);
|
||||
chr = *n + *lineptr - pos;
|
||||
if (!(*lineptr = tmp)) {
|
||||
mem_d (tmp);
|
||||
if (!(*lineptr = (char*)mem_r(*lineptr,(*n+=(*n>16)?*n:64))))
|
||||
return -1;
|
||||
}
|
||||
pos = *n - chr + *lineptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue