Blame SOURCES/023-memory-leak.patch

97a979
From 8034a203bbff0aa3b53f2946dc58e409bd7246c9 Mon Sep 17 00:00:00 2001
97a979
From: Ken Gaillot <kgaillot@redhat.com>
97a979
Date: Thu, 20 Jan 2022 15:03:31 -0600
97a979
Subject: [PATCH] Fix: scheduler: avoid memory leak when displaying clones
97a979
97a979
Previously, pe__clone_default() unconditionally created a hash table for
97a979
stopped instances, but didn't free it in every code path.
97a979
97a979
Now, only create the table when we have something to put in it and might
97a979
actually use it, and ensure it always gets freed.
97a979
---
97a979
 lib/pengine/clone.c | 18 +++++++++++++-----
97a979
 1 file changed, 13 insertions(+), 5 deletions(-)
97a979
97a979
diff --git a/lib/pengine/clone.c b/lib/pengine/clone.c
97a979
index 742e2920b0..920a04c32c 100644
97a979
--- a/lib/pengine/clone.c
97a979
+++ b/lib/pengine/clone.c
97a979
@@ -761,7 +761,7 @@ pe__clone_default(pcmk__output_t *out, va_list args)
97a979
     GList *only_node = va_arg(args, GList *);
97a979
     GList *only_rsc = va_arg(args, GList *);
97a979
 
97a979
-    GHashTable *stopped = pcmk__strkey_table(free, free);
97a979
+    GHashTable *stopped = NULL;
97a979
 
97a979
     char *list_text = NULL;
97a979
     size_t list_text_len = 0;
97a979
@@ -818,7 +818,11 @@ pe__clone_default(pcmk__output_t *out, va_list args)
97a979
         } else if (partially_active == FALSE) {
97a979
             // List stopped instances when requested (except orphans)
97a979
             if (!pcmk_is_set(child_rsc->flags, pe_rsc_orphan)
97a979
+                && !pcmk_is_set(show_opts, pcmk_show_clone_detail)
97a979
                 && pcmk_is_set(show_opts, pcmk_show_inactive_rscs)) {
97a979
+                if (stopped == NULL) {
97a979
+                    stopped = pcmk__strkey_table(free, free);
97a979
+                }
97a979
                 g_hash_table_insert(stopped, strdup(child_rsc->id), strdup("Stopped"));
97a979
             }
97a979
 
97a979
@@ -873,7 +877,6 @@ pe__clone_default(pcmk__output_t *out, va_list args)
97a979
     }
97a979
 
97a979
     if (pcmk_is_set(show_opts, pcmk_show_clone_detail)) {
97a979
-        g_hash_table_destroy(stopped);
97a979
         PCMK__OUTPUT_LIST_FOOTER(out, rc);
97a979
         return pcmk_rc_ok;
97a979
     }
97a979
@@ -948,8 +951,10 @@ pe__clone_default(pcmk__output_t *out, va_list args)
97a979
             GList *list = g_hash_table_get_values(rsc->allowed_nodes);
97a979
 
97a979
             /* Custom stopped table for non-unique clones */
97a979
-            g_hash_table_destroy(stopped);
97a979
-            stopped = pcmk__strkey_table(free, free);
97a979
+            if (stopped != NULL) {
97a979
+                g_hash_table_destroy(stopped);
97a979
+                stopped = NULL;
97a979
+            }
97a979
 
97a979
             if (list == NULL) {
97a979
                 /* Clusters with symmetrical=false haven't calculated allowed_nodes yet
97a979
@@ -972,6 +977,9 @@ pe__clone_default(pcmk__output_t *out, va_list args)
97a979
                         state = "Stopped (disabled)";
97a979
                     }
97a979
 
97a979
+                    if (stopped == NULL) {
97a979
+                        stopped = pcmk__strkey_table(free, free);
97a979
+                    }
97a979
                     if (probe_op != NULL) {
97a979
                         int rc;
97a979
 
97a979
@@ -987,7 +995,7 @@ pe__clone_default(pcmk__output_t *out, va_list args)
97a979
             g_list_free(list);
97a979
         }
97a979
 
97a979
-        if (g_hash_table_size(stopped) > 0) {
97a979
+        if (stopped != NULL) {
97a979
             GList *list = sorted_hash_table_values(stopped);
97a979
 
97a979
             clone_header(out, &rc, rsc, clone_data);
97a979
-- 
97a979
2.27.0
97a979