From fcc57a1185121451d9410920a08da9f10e832f70 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Thu, 22 Nov 2012 21:38:14 +0000 Subject: [PATCH] Fix memory leaks --- Makefile | 2 +- test.c | 15 ++++++--------- util.c | 9 +-------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 13a182a..144fe4c 100644 --- a/Makefile +++ b/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 += \ diff --git a/test.c b/test.c index ed66f9d..442c135 100644 --- a/test.c +++ b/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); } /* diff --git a/util.c b/util.c index 8b54251..0789604 100644 --- a/util.c +++ b/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; } -- 2.39.2