cmark

My personal build of CMark ✏️

Commit
2cbb135cbbc43b330506aaecb04a1177681264d0
Parent
f1035464022a8a4e804f5915e6a1388ea49e3fb3
Author
John MacFarlane <jgm@berkeley.edu>
Date

Better solution for memory leak in `cmark_consolidate_text_nodes`.

This avoids allocating a new string.

Closes #32.

Diffstat

1 file changed, 2 insertions, 4 deletions

Status File Name N° Changes Insertions Deletions
Modified src/iterator.c 6 2 4
diff --git a/src/iterator.c b/src/iterator.c
@@ -121,7 +121,6 @@ void cmark_consolidate_text_nodes(cmark_node *root)
 	cmark_strbuf buf = GH_BUF_INIT;
 	cmark_event_type ev_type;
 	cmark_node *cur, *tmp, *next;
-	char *detached;
 
 	while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
 		cur = cmark_iter_get_node(iter);
@@ -139,11 +138,10 @@ void cmark_consolidate_text_nodes(cmark_node *root)
 				cmark_node_free(tmp);
 				tmp = next;
 			}
-			detached = (char *)cmark_strbuf_detach(&buf);
-			cmark_node_set_literal(cur, detached);
-			free(detached);
+			cmark_node_set_literal(cur, (char *)buf.ptr);
 		}
 	}
 
+	cmark_strbuf_free(&buf);
 	cmark_iter_free(iter);
 }