From 5c92b4ee96b53b3cbf15beacdfea44d04e5f1f70 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 12 May 2024 18:52:27 +0200 Subject: [PATCH] [libdom] Free keyboard and dom related strings --- src/document/libdom/doc.c | 15 ++++----------- src/document/libdom/doc.h | 2 ++ src/document/libdom/renderer2.c | 17 +++++++++++++---- src/document/libdom/renderer2.h | 2 ++ src/main/main.c | 6 ++++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/document/libdom/doc.c b/src/document/libdom/doc.c index c21f1412..c5bfb271 100644 --- a/src/document/libdom/doc.c +++ b/src/document/libdom/doc.c @@ -274,8 +274,8 @@ static enum { static lwc_string *keyb_lwc[KEYB_COUNT]; -static void -initialize_keyb(void) +void +keybstrings_init(void) { int i; @@ -284,13 +284,12 @@ initialize_keyb(void) if (err != lwc_error_ok) { return; - //return _dom_exception_from_lwc_error(err); } } } -static void -finalize_keyb(void) +void +keybstrings_fini(void) { int i; @@ -304,12 +303,6 @@ finalize_keyb(void) unicode_val_T convert_dom_string_to_keycode(dom_string *dom_key) { - static int initialized = 0; - - if (!initialized) { - initialize_keyb(); - initialized = 1; - } if (!dom_key) { return 0; } diff --git a/src/document/libdom/doc.h b/src/document/libdom/doc.h index f46cce2c..fed70dfe 100644 --- a/src/document/libdom/doc.h +++ b/src/document/libdom/doc.h @@ -18,6 +18,8 @@ void *el_match_selector(const char *selector, void *node); void add_lowercase_to_string(struct string *buf, const char *str, int len); bool convert_key_to_dom_string(term_event_key_T key, dom_string **res); unicode_val_T convert_dom_string_to_keycode(dom_string *dom_key); +void keybstrings_init(void); +void keybstrings_fini(void); #ifdef __cplusplus } diff --git a/src/document/libdom/renderer2.c b/src/document/libdom/renderer2.c index 76a33625..dcef7d22 100644 --- a/src/document/libdom/renderer2.c +++ b/src/document/libdom/renderer2.c @@ -24,6 +24,7 @@ #include "util/hash.h" #include "util/string.h" +static int libdom_initialised = 0; static int in_script = 0; static bool @@ -264,11 +265,10 @@ walk_tree(void *mapa, void *mapa_rev, struct string *buf, dom_node *node, bool s void render_xhtml_document(struct cache_entry *cached, struct document *document, struct string *buffer) { - static int initialised = 0; - - if (!initialised) { + if (!libdom_initialised) { corestrings_init(); - initialised = 1; + keybstrings_init(); + libdom_initialised = 1; } if (!document->dom) { @@ -298,6 +298,15 @@ render_xhtml_document(struct cache_entry *cached, struct document *document, str dump_xhtml(cached, document, 0); } +void +free_libdom(void) +{ + if (libdom_initialised) { + keybstrings_fini(); + corestrings_fini(); + } +} + #if 0 static void walk_tree2(struct document *document, dom_node *node) diff --git a/src/document/libdom/renderer2.h b/src/document/libdom/renderer2.h index 9d41b619..4ae8aea0 100644 --- a/src/document/libdom/renderer2.h +++ b/src/document/libdom/renderer2.h @@ -19,6 +19,8 @@ struct node_rect { void render_xhtml_document(struct cache_entry *cached, struct document *document, struct string *buffer); void dump_xhtml(struct cache_entry *cached, struct document *document, int parse); +void free_libdom(void); + #if 0 void walk2(struct document *document); void scan_document(struct document_view *doc_view); diff --git a/src/main/main.c b/src/main/main.c index 450dea7b..a0475c35 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -29,6 +29,9 @@ #include "config/options.h" #include "dialogs/menu.h" #include "document/document.h" +#ifdef CONFIG_LIBDOM +#include "document/libdom/renderer2.h" +#endif #include "intl/charsets.h" #include "intl/libintl.h" #include "main/event.h" @@ -327,6 +330,9 @@ terminate_all_subsystems(void) terminate_osdep(); #ifdef CONFIG_COMBINE free_combined(); +#endif +#ifdef CONFIG_LIBDOM + free_libdom(); #endif clean_temporary_files(); }