From: Lukas Lueg Date: Fri, 7 Nov 2014 22:38:16 +0000 (+0100) Subject: Fixed memory leaks X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=7fc5d3a79deb7bc3ac8faffb6d295c6c3a9154d2;p=smdp.git Fixed memory leaks --- diff --git a/include/markdown.h b/include/markdown.h index d1b81ac..b803f81 100644 --- a/include/markdown.h +++ b/include/markdown.h @@ -82,5 +82,6 @@ line_t *next_line(line_t *prev); slide_t *new_slide(); slide_t *next_slide(slide_t *prev); deck_t *new_deck(); +void free_deck(deck_t *); #endif // !defined( MARKDOWN_H ) diff --git a/src/main.c b/src/main.c index 73bc4e0..e1829a8 100644 --- a/src/main.c +++ b/src/main.c @@ -123,5 +123,7 @@ int main(int argc, char *argv[]) { ncurses_display(deck, notrans, nofade, invert); + free_deck(deck); + return EXIT_SUCCESS; } diff --git a/src/markdown.c b/src/markdown.c index d5dbe19..2db9d68 100644 --- a/src/markdown.c +++ b/src/markdown.c @@ -61,3 +61,28 @@ deck_t *new_deck() { x->slides = x->headers = 0; return x; } + +void free_line(line_t *l) { + line_t *n; + while (l) { + n = l->next; + cstring_delete(l->text); + free(l); + l = n; + } +} + +void free_deck(deck_t *deck) { + slide_t *s, *t; + if (deck == NULL) + return; + s = deck->slide; + while (s) { + free_line(s->line); + t = s->next; + free(s); + s = t; + } + free_line(deck->header); + free(deck); +} diff --git a/src/parser.c b/src/parser.c index 760ef4b..c85af8c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -161,6 +161,7 @@ deck_t *markdown_load(FILE *input) { } } } + cstring_delete(text); slide->lines = lc; deck->slides = sc;