242 lines
7.7 KiB
Diff
242 lines
7.7 KiB
Diff
|
From bee54eba4d9c28d3a7907a3e13a5deeee6bc0916 Mon Sep 17 00:00:00 2001
|
||
|
From: Ken Gaillot <kgaillot@redhat.com>
|
||
|
Date: Tue, 27 Jul 2021 11:01:04 -0500
|
||
|
Subject: [PATCH 1/2] Low: tools: avoid (insignificant) memory leaks
|
||
|
|
||
|
detected by valgrind
|
||
|
---
|
||
|
lib/pacemaker/pcmk_cluster_queries.c | 2 ++
|
||
|
tools/crm_diff.c | 2 +-
|
||
|
tools/crm_resource.c | 33 ++++++++++++++++++++-------------
|
||
|
tools/crm_resource_ban.c | 2 +-
|
||
|
4 files changed, 24 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/lib/pacemaker/pcmk_cluster_queries.c b/lib/pacemaker/pcmk_cluster_queries.c
|
||
|
index c68cf9d..46e5538 100644
|
||
|
--- a/lib/pacemaker/pcmk_cluster_queries.c
|
||
|
+++ b/lib/pacemaker/pcmk_cluster_queries.c
|
||
|
@@ -440,6 +440,7 @@ pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT)
|
||
|
}
|
||
|
rc = the_cib->cmds->signon(the_cib, crm_system_name, cib_command);
|
||
|
if (rc != pcmk_ok) {
|
||
|
+ cib_delete(the_cib);
|
||
|
return pcmk_legacy2rc(rc);
|
||
|
}
|
||
|
|
||
|
@@ -488,6 +489,7 @@ pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT)
|
||
|
free_xml(xml_node);
|
||
|
}
|
||
|
the_cib->cmds->signoff(the_cib);
|
||
|
+ cib_delete(the_cib);
|
||
|
return pcmk_legacy2rc(rc);
|
||
|
}
|
||
|
|
||
|
diff --git a/tools/crm_diff.c b/tools/crm_diff.c
|
||
|
index b37f0ea..9890c10 100644
|
||
|
--- a/tools/crm_diff.c
|
||
|
+++ b/tools/crm_diff.c
|
||
|
@@ -383,5 +383,5 @@ done:
|
||
|
free_xml(object_2);
|
||
|
|
||
|
pcmk__output_and_clear_error(error, NULL);
|
||
|
- return exit_code;
|
||
|
+ crm_exit(exit_code);
|
||
|
}
|
||
|
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
|
||
|
index d8e140f..8ca90cb 100644
|
||
|
--- a/tools/crm_resource.c
|
||
|
+++ b/tools/crm_resource.c
|
||
|
@@ -1081,6 +1081,8 @@ clear_constraints(pcmk__output_t *out, xmlNodePtr *cib_xml_copy)
|
||
|
g_set_error(&error, PCMK__RC_ERROR, rc,
|
||
|
"Could not get modified CIB: %s\n", pcmk_strerror(rc));
|
||
|
g_list_free(before);
|
||
|
+ free_xml(*cib_xml_copy);
|
||
|
+ *cib_xml_copy = NULL;
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
@@ -1232,29 +1234,34 @@ populate_working_set(xmlNodePtr *cib_xml_copy)
|
||
|
|
||
|
if (options.xml_file != NULL) {
|
||
|
*cib_xml_copy = filename2xml(options.xml_file);
|
||
|
+ if (*cib_xml_copy == NULL) {
|
||
|
+ rc = pcmk_rc_cib_corrupt;
|
||
|
+ }
|
||
|
} else {
|
||
|
rc = cib_conn->cmds->query(cib_conn, NULL, cib_xml_copy, cib_scope_local | cib_sync_call);
|
||
|
rc = pcmk_legacy2rc(rc);
|
||
|
}
|
||
|
|
||
|
- if(rc != pcmk_rc_ok) {
|
||
|
- return rc;
|
||
|
+ if (rc == pcmk_rc_ok) {
|
||
|
+ data_set = pe_new_working_set();
|
||
|
+ if (data_set == NULL) {
|
||
|
+ rc = ENOMEM;
|
||
|
+ } else {
|
||
|
+ pe__set_working_set_flags(data_set,
|
||
|
+ pe_flag_no_counts|pe_flag_no_compat);
|
||
|
+ data_set->priv = out;
|
||
|
+ rc = update_working_set_xml(data_set, cib_xml_copy);
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
- /* Populate the working set instance */
|
||
|
- data_set = pe_new_working_set();
|
||
|
- if (data_set == NULL) {
|
||
|
- rc = ENOMEM;
|
||
|
+ if (rc != pcmk_rc_ok) {
|
||
|
+ free_xml(*cib_xml_copy);
|
||
|
+ *cib_xml_copy = NULL;
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
- pe__set_working_set_flags(data_set, pe_flag_no_counts|pe_flag_no_compat);
|
||
|
- data_set->priv = out;
|
||
|
- rc = update_working_set_xml(data_set, cib_xml_copy);
|
||
|
- if (rc == pcmk_rc_ok) {
|
||
|
- cluster_status(data_set);
|
||
|
- }
|
||
|
- return rc;
|
||
|
+ cluster_status(data_set);
|
||
|
+ return pcmk_rc_ok;
|
||
|
}
|
||
|
|
||
|
static int
|
||
|
diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c
|
||
|
index a297d49..2c4f48d 100644
|
||
|
--- a/tools/crm_resource_ban.c
|
||
|
+++ b/tools/crm_resource_ban.c
|
||
|
@@ -292,7 +292,7 @@ resource_clear_node_in_location(const char *rsc_id, const char *host, cib_t * ci
|
||
|
rc = pcmk_legacy2rc(rc);
|
||
|
}
|
||
|
|
||
|
- free(fragment);
|
||
|
+ free_xml(fragment);
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
--
|
||
|
1.8.3.1
|
||
|
|
||
|
|
||
|
From a30ff4a87f291a0c9e03c4efb9c9046d2ac594f1 Mon Sep 17 00:00:00 2001
|
||
|
From: Ken Gaillot <kgaillot@redhat.com>
|
||
|
Date: Tue, 27 Jul 2021 11:26:59 -0500
|
||
|
Subject: [PATCH 2/2] Fix: tools: avoid memory leaks in crm_mon
|
||
|
|
||
|
could be significant in an interactive session
|
||
|
|
||
|
regressions introduced in 2.0.4 and 2.0.5
|
||
|
---
|
||
|
lib/pengine/bundle.c | 3 ++-
|
||
|
lib/pengine/clone.c | 5 ++---
|
||
|
lib/pengine/pe_output.c | 3 +++
|
||
|
3 files changed, 7 insertions(+), 4 deletions(-)
|
||
|
|
||
|
diff --git a/lib/pengine/bundle.c b/lib/pengine/bundle.c
|
||
|
index 6ba786a..7e1d428 100644
|
||
|
--- a/lib/pengine/bundle.c
|
||
|
+++ b/lib/pengine/bundle.c
|
||
|
@@ -1497,7 +1497,7 @@ pe__bundle_xml(pcmk__output_t *out, va_list args)
|
||
|
for (GList *gIter = bundle_data->replicas; gIter != NULL;
|
||
|
gIter = gIter->next) {
|
||
|
pe__bundle_replica_t *replica = gIter->data;
|
||
|
- char *id = pcmk__itoa(replica->offset);
|
||
|
+ char *id = NULL;
|
||
|
gboolean print_ip, print_child, print_ctnr, print_remote;
|
||
|
|
||
|
CRM_ASSERT(replica);
|
||
|
@@ -1531,6 +1531,7 @@ pe__bundle_xml(pcmk__output_t *out, va_list args)
|
||
|
CRM_ASSERT(rc == pcmk_rc_ok);
|
||
|
}
|
||
|
|
||
|
+ id = pcmk__itoa(replica->offset);
|
||
|
rc = pe__name_and_nvpairs_xml(out, true, "replica", 1, "id", id);
|
||
|
free(id);
|
||
|
CRM_ASSERT(rc == pcmk_rc_ok);
|
||
|
diff --git a/lib/pengine/clone.c b/lib/pengine/clone.c
|
||
|
index 6323692..ab91fd1 100644
|
||
|
--- a/lib/pengine/clone.c
|
||
|
+++ b/lib/pengine/clone.c
|
||
|
@@ -807,10 +807,10 @@ pe__clone_html(pcmk__output_t *out, va_list args)
|
||
|
pcmk__add_word(&list_text, &list_text_len, host->details->uname);
|
||
|
active_instances++;
|
||
|
}
|
||
|
+ g_list_free(promoted_list);
|
||
|
|
||
|
if (list_text != NULL) {
|
||
|
out->list_item(out, NULL, PROMOTED_INSTANCES ": [ %s ]", list_text);
|
||
|
- g_list_free(promoted_list);
|
||
|
free(list_text);
|
||
|
list_text = NULL;
|
||
|
list_text_len = 0;
|
||
|
@@ -828,6 +828,7 @@ pe__clone_html(pcmk__output_t *out, va_list args)
|
||
|
pcmk__add_word(&list_text, &list_text_len, host->details->uname);
|
||
|
active_instances++;
|
||
|
}
|
||
|
+ g_list_free(started_list);
|
||
|
|
||
|
if (list_text != NULL) {
|
||
|
if (pcmk_is_set(rsc->flags, pe_rsc_promotable)) {
|
||
|
@@ -847,7 +848,6 @@ pe__clone_html(pcmk__output_t *out, va_list args)
|
||
|
out->list_item(out, NULL, "Started: [ %s ]", list_text);
|
||
|
}
|
||
|
|
||
|
- g_list_free(started_list);
|
||
|
free(list_text);
|
||
|
list_text = NULL;
|
||
|
list_text_len = 0;
|
||
|
@@ -1048,10 +1048,10 @@ pe__clone_text(pcmk__output_t *out, va_list args)
|
||
|
pcmk__add_word(&list_text, &list_text_len, host->details->uname);
|
||
|
active_instances++;
|
||
|
}
|
||
|
+ g_list_free(promoted_list);
|
||
|
|
||
|
if (list_text != NULL) {
|
||
|
out->list_item(out, PROMOTED_INSTANCES, "[ %s ]", list_text);
|
||
|
- g_list_free(promoted_list);
|
||
|
free(list_text);
|
||
|
list_text = NULL;
|
||
|
list_text_len = 0;
|
||
|
@@ -1069,6 +1069,7 @@ pe__clone_text(pcmk__output_t *out, va_list args)
|
||
|
pcmk__add_word(&list_text, &list_text_len, host->details->uname);
|
||
|
active_instances++;
|
||
|
}
|
||
|
+ g_list_free(started_list);
|
||
|
|
||
|
if (list_text != NULL) {
|
||
|
if (pcmk_is_set(rsc->flags, pe_rsc_promotable)) {
|
||
|
@@ -1084,7 +1085,6 @@ pe__clone_text(pcmk__output_t *out, va_list args)
|
||
|
out->list_item(out, "Started", "[ %s ]", list_text);
|
||
|
}
|
||
|
|
||
|
- g_list_free(started_list);
|
||
|
free(list_text);
|
||
|
list_text = NULL;
|
||
|
}
|
||
|
diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c
|
||
|
index b8997c4..20bd1a9 100644
|
||
|
--- a/lib/pengine/pe_output.c
|
||
|
+++ b/lib/pengine/pe_output.c
|
||
|
@@ -1410,6 +1410,8 @@ node_text(pcmk__output_t *out, va_list args) {
|
||
|
|
||
|
out->end_list(out);
|
||
|
out->end_list(out);
|
||
|
+
|
||
|
+ g_list_free(rscs);
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
@@ -1739,6 +1741,7 @@ node_attribute_list(pcmk__output_t *out, va_list args) {
|
||
|
}
|
||
|
|
||
|
if (!pcmk__str_in_list(only_node, node->details->uname)) {
|
||
|
+ g_list_free(attr_list);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
--
|
||
|
1.8.3.1
|
||
|
|