File pacemaker#3380-0003-Low-libcrmcommon-Use-free_xml-in-html_free_priv.patch of Package pacemaker.36873
From 099ce22bb245c5edaa868cb007b8c2a00304c527 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Fri, 1 Mar 2024 10:32:01 -0500
Subject: [PATCH 3/3] Low: libcrmcommon: Use free_xml in html_free_priv.
Also, add comments in various spots explaining why we cannot free
certain things.
---
lib/common/output_html.c | 10 ++++++++--
lib/common/output_xml.c | 7 +++++++
2 files changed, 15 insertions(+), 2 deletions(-)
Index: pacemaker-2.0.5+20201202.ba59be712/lib/common/output_html.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/common/output_html.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/common/output_html.c
@@ -69,7 +69,11 @@ html_free_priv(pcmk__output_t *out) {
return;
}
- xmlFreeNode(priv->root);
+ free_xml(priv->root);
+ /* The elements of parent_q are xmlNodes that are a part of the
+ * priv->root document, so the above line already frees them. Don't
+ * call g_queue_free_full here.
+ */
g_queue_free(priv->parent_q);
g_slist_free_full(priv->errors, free);
free(priv);
@@ -353,7 +357,9 @@ html_end_list(pcmk__output_t *out) {
CRM_ASSERT(priv != NULL);
- /* Remove the <ul> tag. */
+ /* Remove the <ul> tag, but do not free this result - it's still
+ * part of the document.
+ */
g_queue_pop_tail(priv->parent_q);
pcmk__output_xml_pop_parent(out);
Index: pacemaker-2.0.5+20201202.ba59be712/lib/common/output_xml.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/common/output_xml.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/common/output_xml.c
@@ -83,6 +83,10 @@ xml_free_priv(pcmk__output_t *out) {
}
free_xml(priv->root);
+ /* The elements of parent_q are xmlNodes that are a part of the
+ * priv->root document, so the above line already frees them. Don't
+ * call g_queue_free_full here.
+ */
g_queue_free(priv->parent_q);
g_slist_free_full(priv->errors, free);
free(priv);
@@ -357,11 +361,13 @@ xml_end_list(pcmk__output_t *out) {
CRM_ASSERT(priv != NULL);
if (priv->legacy_xml || simple_list) {
+ /* Do not free node here - it's still part of the document */
g_queue_pop_tail(priv->parent_q);
} else {
char *buf = NULL;
xmlNodePtr node;
+ /* Do not free this result - it's still part of the document */
node = g_queue_pop_tail(priv->parent_q);
buf = crm_strdup_printf("%lu", xmlChildElementCount(node));
xmlSetProp(node, (pcmkXmlStr) "count", (pcmkXmlStr) buf);
@@ -459,6 +465,7 @@ pcmk__output_xml_pop_parent(pcmk__output
CRM_ASSERT(priv != NULL);
CRM_ASSERT(g_queue_get_length(priv->parent_q) > 0);
+ /* Do not free this result - it's still part of the document */
g_queue_pop_tail(priv->parent_q);
}