From 8b76c1331d22c57aeda03e562ab385b067d36166 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 18 Jul 2021 13:35:31 +0200 Subject: [PATCH] [document] free text allocated by renderer2 --- src/document/document.c | 2 ++ src/document/document.h | 1 + src/document/xml/renderer2.c | 14 ++++++++------ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/document/document.c b/src/document/document.c index c94468602..80e528f50 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -267,6 +267,7 @@ reset_document(struct document *document) #ifdef CONFIG_ECMASCRIPT free_string_list(&document->onload_snippets); free_uri_list(&document->ecmascript_imports); + mem_free_set(&document->text, NULL); /// kill_timer(&document->timeout); /// free_document(document->dom); #endif @@ -332,6 +333,7 @@ done_document(struct document *document) free_string_list(&document->onload_snippets); free_uri_list(&document->ecmascript_imports); kill_timer(&document->timeout); + mem_free_if(document->text); free_document(document->dom); #endif diff --git a/src/document/document.h b/src/document/document.h index 3d2939fac..6bf30e863 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -212,6 +212,7 @@ struct document { timer_id_T timeout; int ecmascript_counter; void *dom; + char *text; #endif #ifdef CONFIG_CSS /** @todo FIXME: We should externally maybe using cache_entry store the diff --git a/src/document/xml/renderer2.c b/src/document/xml/renderer2.c index 0a0bc6ca7..34ccd5b80 100644 --- a/src/document/xml/renderer2.c +++ b/src/document/xml/renderer2.c @@ -281,16 +281,11 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str } struct string head; - struct string tt; assert(cached && document); if_assert_failed return; if (!init_string(&head)) return; - if (!init_string(&tt)) { - done_string(&head); - return; - } add_to_string(&head, "\r\nContent-Type: text/html; charset=utf-8\r\n"); @@ -298,9 +293,16 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str if (!buffer) { std::string text = doc->write_to_string_formatted(); + struct string tt; + + if (!init_string(&tt)) { + done_string(&head); + return; + } add_bytes_to_string(&tt, text.c_str(), text.size()); buffer = &tt; + document->text = tt.source; } mem_free_set(&cached->head, head.source); render_html_document(cached, document, buffer); -} \ No newline at end of file +}