From 41074ac1cac44bec3cd530340c53a8bbae6b4bc6 Mon Sep 17 00:00:00 2001
From: Witold Filipczyk <witekfl@poczta.onet.pl>
Date: Sun, 28 May 2023 16:50:19 +0200
Subject: [PATCH] [dom] Bad function for unref caused memory leak.

---
 src/document/libdom/renderer.c  | 4 ++--
 src/document/libdom/renderer2.c | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/document/libdom/renderer.c b/src/document/libdom/renderer.c
index d1245b60b..46f446a04 100644
--- a/src/document/libdom/renderer.c
+++ b/src/document/libdom/renderer.c
@@ -106,7 +106,7 @@ dump_dom_element(void *mapa, struct string *buf, dom_node *node, int depth)
 	dom_exception exc;
 	dom_string *node_name = NULL;
 	dom_node_type type;
-	dom_namednodemap *attrs;
+	dom_namednodemap *attrs = NULL;
 
 	/* Only interested in element nodes */
 	exc = dom_node_get_node_type(node, &type);
@@ -169,7 +169,7 @@ dump_dom_element(void *mapa, struct string *buf, dom_node *node, int depth)
 				}
 			}
 		}
-		dom_node_unref(attrs);
+		dom_namednodemap_unref(attrs);
 	}
 	add_char_to_string(buf, '>');
 
diff --git a/src/document/libdom/renderer2.c b/src/document/libdom/renderer2.c
index 16e35e520..5499e7888 100644
--- a/src/document/libdom/renderer2.c
+++ b/src/document/libdom/renderer2.c
@@ -108,7 +108,7 @@ dump_dom_element(void *mapa, struct string *buf, dom_node *node, int depth)
 	dom_exception exc;
 	dom_string *node_name = NULL;
 	dom_node_type type;
-	dom_namednodemap *attrs;
+	dom_namednodemap *attrs = NULL;
 
 	/* Only interested in element nodes */
 	exc = dom_node_get_node_type(node, &type);
@@ -171,7 +171,9 @@ dump_dom_element(void *mapa, struct string *buf, dom_node *node, int depth)
 				}
 			}
 		}
-		dom_node_unref(attrs);
+	}
+	if (attrs) {
+		dom_namednodemap_unref(attrs);
 	}
 	add_char_to_string(buf, '>');