Blame SOURCES/095-attrd-client-leak.patch

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