Browse Source

fixed memory leak and some small changes

master
Chris Cromer 3 years ago
parent
commit
8361f1071a
3 changed files with 11 additions and 7 deletions
  1. +4
    -0
      AUTHORS
  2. +1
    -1
      src/main.c
  3. +6
    -6
      src/readfile.c

+ 4
- 0
AUTHORS View File

@@ -0,0 +1,4 @@
Authors of generarxml.

Chris Cromer
Wrote everything

+ 1
- 1
src/main.c View File

@@ -161,5 +161,5 @@ void printusage(int error) {

printf("usage: generarxml [opciones] \n");
printf(" -c, --config <archivo> 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");*/
}

+ 6
- 6
src/readfile.c View File

@@ -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++) {

Loading…
Cancel
Save