From 29fbcd6e5715944b458965535bdd5bc302cc0996 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 24 Oct 2014 10:09:30 -0700 Subject: Fixed memory leak by freeing all unused emphasis openers. --- src/inlines.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/inlines.c b/src/inlines.c index a736ec6..d24235a 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -301,6 +301,7 @@ static node_inl* handle_strong_emph(subject* subj, char c, node_inl **last) int numdelims; int useDelims; inline_stack * istack; + inline_stack * tempstack; node_inl * inl; node_inl * emph; node_inl * inl_text; @@ -336,10 +337,13 @@ static node_inl* handle_strong_emph(subject* subj, char c, node_inl **last) inl->content.inlines = inl->next; inl->next = NULL; - subj->emphasis_openers = istack->previous; - istack->previous = NULL; + // remove this opener and all later ones from stack: + while (subj->emphasis_openers != istack->previous) { + tempstack = subj->emphasis_openers; + free(tempstack); + subj->emphasis_openers = subj->emphasis_openers->previous; + } *last = inl; - free(istack); } else { @@ -350,6 +354,15 @@ static node_inl* handle_strong_emph(subject* subj, char c, node_inl **last) emph = useDelims == 1 ? make_emph(inl->next) : make_strong(inl->next); inl->next = emph; + + // remove all later openers from stack: + while (subj->emphasis_openers != istack) { + tempstack = subj->emphasis_openers; + free(tempstack); + subj->emphasis_openers = subj->emphasis_openers->previous; + } + + *last = emph; } -- cgit v1.2.3