File pacemaker#3380-0003-Low-libcrmcommon-Use-free_xml-in-html_free_priv.patch of Package pacemaker.34780

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.2+20211124.ada5c3b36/lib/common/output_html.c
===================================================================
--- pacemaker-2.1.2+20211124.ada5c3b36.orig/lib/common/output_html.c
+++ pacemaker-2.1.2+20211124.ada5c3b36/lib/common/output_html.c
@@ -73,7 +73,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);
@@ -349,7 +353,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.2+20211124.ada5c3b36/lib/common/output_xml.c
===================================================================
--- pacemaker-2.1.2+20211124.ada5c3b36.orig/lib/common/output_xml.c
+++ pacemaker-2.1.2+20211124.ada5c3b36/lib/common/output_xml.c
@@ -88,6 +88,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);
@@ -361,11 +365,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);
@@ -518,6 +524,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);
 }
 
openSUSE Build Service is sponsored by