File pacemaker#3380-0003-Low-libcrmcommon-Use-free_xml-in-html_free_priv.patch of Package pacemaker.38493
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.1.7+20231219.0f7f88312/lib/common/output_html.c
===================================================================
--- pacemaker-2.1.7+20231219.0f7f88312.orig/lib/common/output_html.c
+++ pacemaker-2.1.7+20231219.0f7f88312/lib/common/output_html.c
@@ -81,7 +81,11 @@ html_free_priv(pcmk__output_t *out) {
priv = out->priv;
- 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);
@@ -365,7 +369,9 @@ html_end_list(pcmk__output_t *out) {
CRM_ASSERT(out != NULL && out->priv != NULL);
priv = out->priv;
- /* 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.1.7+20231219.0f7f88312/lib/common/output_xml.c
===================================================================
--- pacemaker-2.1.7+20231219.0f7f88312.orig/lib/common/output_xml.c
+++ pacemaker-2.1.7+20231219.0f7f88312/lib/common/output_xml.c
@@ -95,6 +95,10 @@ xml_free_priv(pcmk__output_t *out) {
priv = out->priv;
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);
@@ -370,11 +374,13 @@ xml_end_list(pcmk__output_t *out) {
priv = out->priv;
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));
crm_xml_add(node, "count", buf);
@@ -526,6 +532,7 @@ pcmk__output_xml_pop_parent(pcmk__output
priv = out->priv;
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);
}