Browse Source

fixed memory leak and some small changes

Chris Cromer 2 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 @@
1
+Authors of generarxml.
2
+
3
+Chris Cromer
4
+  Wrote everything

+ 1
- 1
src/main.c View File

@@ -161,5 +161,5 @@ void printusage(int error) {
161 161
 
162 162
 	printf("usage: generarxml [opciones] \n");
163 163
     printf("  -c, --config <archivo>    archivo de configuración\n");
164
-    printf("  -s, --significado         imprimir el significado de la vida\n");
164
+    /*printf("  -s, --significado         imprimir el significado de la vida\n");*/
165 165
 }

+ 6
- 6
src/readfile.c View File

@@ -59,15 +59,12 @@ int readfile(CONFIG *config) {
59 59
             line[chars] = '\0';
60 60
         }
61 61
         line[chars] = '\0';
62
-        lines++;
63 62
         array[lines] = strdup(line);
63
+        lines++;
64 64
 
65 65
         /* not enough memory for more lines, time to allocate more memory */
66 66
         if (lines == new_max) {
67
-            /* uses more memory but runs faster */
68
-            /*new_max = new_max * 2;*/
69
-            /* uses less memory but runs slower */ 
70
-            new_max = new_max + MAX_LINES;
67
+            new_max = new_max * 2;
71 68
             char **tmp = realloc(array, new_max * sizeof(*array));
72 69
             if (!tmp) {
73 70
                 fprintf(stderr, "Reallocación de memoria falló.");
@@ -95,7 +92,9 @@ int readfile(CONFIG *config) {
95 92
     }
96 93
 
97 94
     for (j = 0; j < lines; j++) {
98
-        line = latin2utf8(array[j]);
95
+        if (array[j] != NULL) {
96
+            line = latin2utf8(array[j]);
97
+        }
99 98
         /* printf("  array [%lu]  %s\n", (long) j, line); */
100 99
         if (line != NULL) {
101 100
             if (strcmp(line, config->bible) == 0) {
@@ -110,6 +109,7 @@ int readfile(CONFIG *config) {
110 109
             }
111 110
         }
112 111
         free(line);
112
+        line = NULL;
113 113
     }
114 114
 
115 115
     for (j = 0; j < lines; j++) {

Loading…
Cancel
Save