commit 6da988820b4410d7a4a735cd78a33135d806942f from: Omar Polo date: Sun May 20 08:03:31 2018 UTC memory leak fixed commit - 0ee198aa88e8b1f2956614140e7940f3b8805bfd commit + 6da988820b4410d7a4a735cd78a33135d806942f blob - 6e7f6f532c68a386316a5ec0f944b347f8646323 blob + 75404a9f488ac60c33402ba2faa2076ea7ca4b3b --- mymenu.c +++ mymenu.c @@ -264,8 +264,10 @@ int readlines (char ***lns, int items) { while (true) { lines[n] = readline(&finished); - if (strlen(lines[n]) == 0 || lines[n][0] == '\n') + if (strlen(lines[n]) == 0 || lines[n][0] == '\n') { + free(lines[n]); --n; // forget about this line + } if (finished) break; @@ -505,7 +507,7 @@ int parse_int_with_middle(const char *str, int default int main() { /* char *lines[INITIAL_ITEMS] = {0}; */ char **lines = calloc(INITIAL_ITEMS, sizeof(char*)); - readlines(&lines, INITIAL_ITEMS); + int nlines = readlines(&lines, INITIAL_ITEMS); setlocale(LC_ALL, getenv("LANG")); @@ -917,6 +919,10 @@ int main() { if (status == OK) printf("%s\n", text); + + for (int i = 0; i < nlines; ++i) { + free(lines[i]); + } free(fontname); free(text);