From 8361f1071a12ec49da051c7707eae0b4470bfbf8 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Mon, 17 Oct 2016 21:42:58 -0300 Subject: [PATCH] fixed memory leak and some small changes --- AUTHORS | 4 ++++ src/main.c | 2 +- src/readfile.c | 12 ++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index e69de29..b0f04fc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -0,0 +1,4 @@ +Authors of generarxml. + +Chris Cromer + Wrote everything diff --git a/src/main.c b/src/main.c index cabe45a..e916015 100644 --- a/src/main.c +++ b/src/main.c @@ -161,5 +161,5 @@ void printusage(int error) { printf("usage: generarxml [opciones] \n"); printf(" -c, --config archivo de configuración\n"); - printf(" -s, --significado imprimir el significado de la vida\n"); + /*printf(" -s, --significado imprimir el significado de la vida\n");*/ } diff --git a/src/readfile.c b/src/readfile.c index 9d4d1ba..1ea5713 100644 --- a/src/readfile.c +++ b/src/readfile.c @@ -59,15 +59,12 @@ int readfile(CONFIG *config) { line[chars] = '\0'; } line[chars] = '\0'; - lines++; array[lines] = strdup(line); + lines++; /* not enough memory for more lines, time to allocate more memory */ if (lines == new_max) { - /* uses more memory but runs faster */ - /*new_max = new_max * 2;*/ - /* uses less memory but runs slower */ - new_max = new_max + MAX_LINES; + new_max = new_max * 2; char **tmp = realloc(array, new_max * sizeof(*array)); if (!tmp) { fprintf(stderr, "Reallocación de memoria falló."); @@ -95,7 +92,9 @@ int readfile(CONFIG *config) { } for (j = 0; j < lines; j++) { - line = latin2utf8(array[j]); + if (array[j] != NULL) { + line = latin2utf8(array[j]); + } /* printf(" array [%lu] %s\n", (long) j, line); */ if (line != NULL) { if (strcmp(line, config->bible) == 0) { @@ -110,6 +109,7 @@ int readfile(CONFIG *config) { } } free(line); + line = NULL; } for (j = 0; j < lines; j++) {