summaryrefslogtreecommitdiff
path: root/src/inlines.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-10-24 10:09:30 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-10-24 10:09:30 -0700
commit29fbcd6e5715944b458965535bdd5bc302cc0996 (patch)
tree848110adae9e085ffa41b458525d2ac6aa13c166 /src/inlines.c
parent751fb7894ccca3a89c4f14cb5c99ff39be957455 (diff)
Fixed memory leak by freeing all unused emphasis openers.
Diffstat (limited to 'src/inlines.c')
-rw-r--r--src/inlines.c19
1 files 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;
}