From 4f878f0d0e50c6f8fe320635ad9ab635c8e3108a Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Thu, 16 Feb 2017 19:48:36 -0500 Subject: [PATCH] FIXED: Fix memory leaks etc --- src/beamer.c | 9 ++------- src/latex.c | 23 +++-------------------- src/memoir.c | 8 -------- src/mmd.c | 1 - src/scanners.c | 4 +--- src/scanners.re | 2 -- src/writer.c | 17 +++++++++++------ 7 files changed, 17 insertions(+), 47 deletions(-) diff --git a/src/beamer.c b/src/beamer.c index 656fed2..4bc6157 100644 --- a/src/beamer.c +++ b/src/beamer.c @@ -76,6 +76,7 @@ void mmd_outline_add_beamer(DString * out, token * current, scratch_pad * scratc break; case BLOCK_SETEXT_2: level = 2; + break; default: level = 1 + current->type - BLOCK_H1; } @@ -95,6 +96,7 @@ void mmd_outline_add_beamer(DString * out, token * current, scratch_pad * scratc break; case BLOCK_SETEXT_2: t_level = 2; + break; default: t_level = 1 + t->type - BLOCK_H1; } @@ -149,14 +151,8 @@ void mmd_export_token_beamer(DString * out, const char * source, token * t, scra return; short temp_short; - short temp_short2; - link * temp_link = NULL; char * temp_char = NULL; - char * temp_char2 = NULL; - char * temp_char3 = NULL; - bool temp_bool = 0; token * temp_token = NULL; - footnote * temp_note = NULL; switch (t->type) { case DOC_START_TOKEN: @@ -290,7 +286,6 @@ void mmd_export_citation_list_beamer(DString * out, const char * source, scratch pad(out, 2, scratch); note = stack_peek_index(scratch->used_citations, i); - content = note->content; printf("\\bibitem{%s}\n", note->label_text); scratch->padded = 6; diff --git a/src/latex.c b/src/latex.c index 0d00a2a..ac8d28d 100644 --- a/src/latex.c +++ b/src/latex.c @@ -204,7 +204,6 @@ void mmd_print_localized_char_latex(DString * out, unsigned short type, scratch_ void mmd_export_link_latex(DString * out, const char * source, token * text, link * link, scratch_pad * scratch) { - attr * a = link->attributes; char * temp_char; if (link->url) { @@ -234,21 +233,6 @@ void mmd_export_link_latex(DString * out, const char * source, token * text, lin } else print("\\href{}"); -// if (link->title && link->title[0] != '\0') { -// print(" title=\""); -// mmd_print_string_latex(out, link->title); -// print("\""); -// } - -// while (a) { -// print(" "); -// print(a->key); -// print("=\""); -// print(a->value); -// print("\""); -// a = a->next; -// } - print("{"); // If we're printing contents of bracket as text, then ensure we include it all @@ -1367,10 +1351,10 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat if (t->next && t->next->type == TABLE_DIVIDER) { t = t->next; - if (t->next && t->next->type == TABLE_CELL) + if (t->next && t->next->type == TABLE_CELL) { print("&"); - - scratch->table_cell_count += t->next->len; + scratch->table_cell_count += t->next->len; + } } else scratch->table_cell_count++; @@ -1669,7 +1653,6 @@ void mmd_export_citation_list_latex(DString * out, const char * source, scratch_ scratch->footnote_para_counter = 0; - content = note->content; scratch->citation_being_printed = i + 1; mmd_export_token_tree_latex(out, source, content, scratch); diff --git a/src/memoir.c b/src/memoir.c index 841cee1..2416619 100644 --- a/src/memoir.c +++ b/src/memoir.c @@ -67,15 +67,7 @@ void mmd_export_token_memoir(DString * out, const char * source, token * t, scra if (t == NULL) return; - short temp_short; - short temp_short2; - link * temp_link = NULL; char * temp_char = NULL; - char * temp_char2 = NULL; - char * temp_char3 = NULL; - bool temp_bool = 0; - token * temp_token = NULL; - footnote * temp_note = NULL; switch (t->type) { case DOC_START_TOKEN: diff --git a/src/mmd.c b/src/mmd.c index 5137ac1..e08948b 100644 --- a/src/mmd.c +++ b/src/mmd.c @@ -1693,7 +1693,6 @@ void strip_line_tokens_from_block(mmd_engine * e, token * block) { goto handle_line; } default: - handle_block: //fprintf(stderr, "Unspecified line type %d inside block type %d\n", l->type, block->type); // This is a block, need to remove it from chain and // Add to parent diff --git a/src/scanners.c b/src/scanners.c index 38de820..d80a386 100644 --- a/src/scanners.c +++ b/src/scanners.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Mon Feb 13 09:48:30 2017 */ +/* Generated by re2c 0.14.3 on Thu Feb 16 19:37:08 2017 */ /** MultiMarkdown 6 -- Lightweight markup processor to produce HTML, LaTeX, and more. @@ -8876,7 +8876,6 @@ yy650: size_t scan_meta_key(const char * c) { - const char * marker = NULL; const char * start = c; @@ -9489,7 +9488,6 @@ yy734: size_t scan_destination(const char * c) { - const char * marker = NULL; const char * start = c; diff --git a/src/scanners.re b/src/scanners.re index 0b61532..ad1d274 100644 --- a/src/scanners.re +++ b/src/scanners.re @@ -353,7 +353,6 @@ size_t scan_meta_line(const char * c) { size_t scan_meta_key(const char * c) { - const char * marker = NULL; const char * start = c; /*!re2c @@ -403,7 +402,6 @@ size_t scan_alignment_string(const char * c) { size_t scan_destination(const char * c) { - const char * marker = NULL; const char * start = c; /*!re2c diff --git a/src/writer.c b/src/writer.c index b96dcd7..f041e7f 100644 --- a/src/writer.c +++ b/src/writer.c @@ -258,11 +258,12 @@ char * text_inside_pair(const char * source, token * pair) { char * result = NULL; if (source && pair) { - if (pair->child->mate) { + if (pair->child && pair->child->mate) { // [foo], [^foo], [#foo] should give different strings -- use closer len result = strndup(&source[pair->start + pair->child->mate->len], pair->len - (pair->child->mate->len * 2)); } else { - result = strndup(&source[pair->start + pair->child->len], pair->len - (pair->child->len + 1)); + if (pair->child) + result = strndup(&source[pair->start + pair->child->len], pair->len - (pair->child->len + 1)); } } @@ -1454,9 +1455,13 @@ void parse_brackets(const char * source, scratch_pad * scratch, token * bracket, if (temp_link) { // Don't output brackets - bracket->child->type = TEXT_EMPTY; - bracket->child->mate->type = TEXT_EMPTY; - + if (bracket->child) { + bracket->child->type = TEXT_EMPTY; + + if (bracket->child->mate) + bracket->child->mate->type = TEXT_EMPTY; + } + *final_link = temp_link; // Skip over second bracket if present @@ -1707,7 +1712,7 @@ bool table_has_caption(token * t) { (t->next->type == TEXT_LINEBREAK))) t = t->next; - if (t->next == NULL) + if (t && t->next == NULL) return true; } }