aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-05 10:12:46 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-05 10:12:46 -0800
commitca1e1cde8693b16907efe19b2b9ea9d61dbf3129 (patch)
treedbc200b4314938a341a26275a7ac1b514aff053c /src
parent715d1a5921a4e3e10220d466c4ee2c1261d28c1e (diff)
Made cmark_free_nodes non-recursive.
See #187.
Diffstat (limited to 'src')
-rw-r--r--src/blocks.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 7613c82..e8c9e94 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -252,12 +252,13 @@ static node_block* add_child(node_block* parent,
return child;
}
+
// Free a node_block list and any children.
void cmark_free_nodes(node_block *e)
{
node_block * next;
+ node_block * tmp;
while (e != NULL) {
- next = e->next;
free_inlines(e->inline_content);
strbuf_free(&e->string_content);
if (e->tag == BLOCK_FENCED_CODE) {
@@ -265,7 +266,17 @@ void cmark_free_nodes(node_block *e)
} else if (e->tag == BLOCK_DOCUMENT) {
reference_map_free(e->as.document.refmap);
}
- cmark_free_nodes(e->children);
+ tmp = e->children;
+ if (tmp) {
+ // Find last child
+ while (tmp->next) {
+ tmp = tmp->next;
+ }
+ // Splice children into list
+ tmp->next = e->next;
+ e->next = e->children;
+ }
+ next = e->next;
free(e);
e = next;
}