Added free() calls

This commit is contained in:
zenon 2018-05-21 18:32:21 +02:00
parent 3a27588d6f
commit 9219f8f097

View File

@ -123,17 +123,17 @@ struct Graph *parse(int argc, char *argv[])
fprintf(stderr, "[%s] An edge consists of two " fprintf(stderr, "[%s] An edge consists of two "
"nodes separated by a dash\n", pname); "nodes separated by a dash\n", pname);
free(str); free(str);
exit(EXIT_FAILURE); return NULL;
} }
switch (src) { switch (src) {
case -2: case -2:
free(str); free(str);
exit(EXIT_FAILURE); return NULL;
break; break;
case -1: case -1:
fprintf(stderr, "%s\n", edge); fprintf(stderr, "%s\n", edge);
free(str); free(str);
exit(EXIT_FAILURE); return NULL;
break; break;
default: default:
break; break;
@ -141,6 +141,7 @@ struct Graph *parse(int argc, char *argv[])
count++; count++;
} }
free(str);
} }
struct Graph *graph = createGraph(V+1); struct Graph *graph = createGraph(V+1);
@ -176,9 +177,21 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa, NULL); sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL); sigaction(SIGTERM, &sa, NULL);
struct Graph *graph;
while (quit == 0) { while (quit == 0) {
struct Graph *graph = parse(argc, argv); graph = parse(argc, argv);
if (graph == NULL) {
for (int i = 0; i < graph->V; i++) {
free(graph->array[i].head);
}
free(graph->array);
free(graph);
exit(EXIT_FAILURE);
}
printGraph(graph); printGraph(graph);
free(graph->array);
free(graph);
break; break;
} }