From b41b23a7f3cd668512401a539fdf75f98d9a1d74 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Sat, 30 Sep 2017 14:51:43 -0500
Subject: [PATCH] Low: libcrmcommon: avoid memory leak in attrd_get_target()
---
lib/common/utils.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/lib/common/utils.c b/lib/common/utils.c
index 290a661..4c02869 100644
--- a/lib/common/utils.c
+++ b/lib/common/utils.c
@@ -2157,6 +2157,8 @@ attrd_clear_delegate(crm_ipc_t *ipc, const char *host, const char *resource,
}
#endif
+#define LRM_TARGET_ENV "OCF_RESKEY_" CRM_META "_" XML_LRM_ATTR_TARGET
+
const char *
attrd_get_target(const char *name)
{
@@ -2168,19 +2170,27 @@ attrd_get_target(const char *name)
return name;
} else {
- const char *target = getenv(crm_meta_name(XML_RSC_ATTR_TARGET));
- const char *host_pyhsical = getenv(crm_meta_name(PCMK_ENV_PHYSICAL_HOST));
- const char *host_pcmk = getenv("OCF_RESKEY_" CRM_META "_" XML_LRM_ATTR_TARGET);
+ char *target_var = crm_meta_name(XML_RSC_ATTR_TARGET);
+ char *phys_var = crm_meta_name(PCMK_ENV_PHYSICAL_HOST);
+ const char *target = getenv(target_var);
+ const char *host_physical = getenv(phys_var);
/* It is important we use the names by which the PE knows us */
- if(safe_str_eq(target, "host") && host_pyhsical != NULL) {
- return host_pyhsical;
+ if (host_physical && safe_str_eq(target, "host")) {
+ name = host_physical;
+
+ } else {
+ const char *host_pcmk = getenv(LRM_TARGET_ENV);
- } else if(host_pcmk) {
- return host_pcmk;
+ if (host_pcmk) {
+ name = host_pcmk;
+ }
}
+ free(target_var);
+ free(phys_var);
}
// TODO? Call get_local_node_name() if name == NULL
+ // (currently would require linkage against libcrmcluster)
return name;
}
--
1.8.3.1