prevent use-after-free
authorMichael Göhler <somebody.here@gmx.de>
Thu, 18 Sep 2014 20:26:54 +0000 (22:26 +0200)
committerMichael Göhler <somebody.here@gmx.de>
Thu, 18 Sep 2014 20:26:54 +0000 (22:26 +0200)
parser.c

index 9c5d628..8489ab0 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -40,6 +40,7 @@ deck_t *markdown_load(FILE *input) {
     deck_t *deck = new_deck();
     slide_t *slide = new_slide();
     line_t *line = NULL;
+    line_t *tmp = NULL;
     cstring_t *text = cstring_init();
 
     // assign first slide to deck
@@ -198,7 +199,7 @@ deck_t *markdown_load(FILE *input) {
                 if(line->next)
                     line->next->prev = line->prev;
 
-                // set bits on revious line
+                // set bits on previous line
                 if(CHECK_BIT(line->bits, IS_H1)) {
                     SET_BIT(line->prev->bits, IS_H1);
                 } else {
@@ -208,9 +209,13 @@ deck_t *markdown_load(FILE *input) {
                 // adjust line count
                 slide->lines -= 1;
 
+                // maintain loop condition
+                tmp = line;
+                line = line->prev;
+
                 // delete line
-                (line->text->delete)(line->text);
-                free(line);
+                (tmp->text->delete)(tmp->text);
+                free(tmp);
             }
             line = line->next;
         }