summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch')
-rw-r--r--meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch103
1 files changed, 103 insertions, 0 deletions
diff --git a/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch b/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch
new file mode 100644
index 000000000..fcc5d8ebf
--- /dev/null
+++ b/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch
@@ -0,0 +1,103 @@
1From 17e1ee2539cea6bac16832b488afd52b20a348ac Mon Sep 17 00:00:00 2001
2From: Rainer Gerhards <rgerhards@adiscon.com>
3Date: Mon, 28 Oct 2013 14:17:56 +0100
4Subject: [PATCH] remove memleak introduced by GenerateLocalHostName HUP
5 bugfix
6
7Upstream-Status: backport
8
9Signed-off-by: Li Zhou <li.zhou@windriver.com>
10---
11 runtime/glbl.c | 45 ++++++++++++++++++++++++++++++++-------------
12 1 file changed, 32 insertions(+), 13 deletions(-)
13
14diff --git a/runtime/glbl.c b/runtime/glbl.c
15index bcb3795..41d56c2 100644
16--- a/runtime/glbl.c
17+++ b/runtime/glbl.c
18@@ -72,6 +72,7 @@ static int option_DisallowWarning = 1; /* complain if message from disallowed se
19 static int bDisableDNS = 0; /* don't look up IP addresses of remote messages */
20 static prop_t *propLocalIPIF = NULL;/* IP address to report for the local host (default is 127.0.0.1) */
21 static prop_t *propLocalHostName = NULL;/* our hostname as FQDN - read-only after startup */
22+static prop_t *propLocalHostNameToDelete = NULL;/* see GenerateLocalHostName function hdr comment! */
23 static uchar *LocalHostName = NULL;/* our hostname - read-only after startup, except HUP */
24 static uchar *LocalHostNameOverride = NULL;/* user-overridden hostname - read-only after startup */
25 static uchar *LocalFQDNName = NULL;/* our hostname as FQDN - read-only after startup, except HUP */
26@@ -380,24 +381,31 @@ GetLocalDomain(void)
27 /* generate the local hostname property. This must be done after the hostname info
28 * has been set as well as PreserveFQDN.
29 * rgerhards, 2009-06-30
30- * NOTE: This function DELIBERATELY introduces a small memory leak in order to gain
31- * speed. Each time it is called when a property name already exists, a new one is
32- * allocated but the previous one is NOT freed. This is so that current readers can
33- * continue to use the previous name. Otherwise, we would need to use read/write locks
34- * to protect the update process. As this function is called extremely infrequently and
35- * the memory leak is very small, this is totally accessible. Think that otherwise we
36- * would need to place a read look each time the property is read, which is much more
37- * frequent (once per message for the modules that use this local hostname!).
38+ * NOTE: This function tries to avoid locking by not destructing the previous value
39+ * immediately. This is so that current readers can continue to use the previous name.
40+ * Otherwise, we would need to use read/write locks to protect the update process.
41+ * In order to do so, we save the previous value and delete it when we are called again
42+ * the next time. Note that this in theory is racy and can lead to a double-free.
43+ * In practice, however, the window of exposure to trigger this is extremely short
44+ * and as this functions is very infrequently being called (on HUP), the trigger
45+ * condition for this bug is so highly unlikely that it never occurs in practice.
46+ * Probably if you HUP rsyslog every few milliseconds, but who does that...
47+ * To further reduce risk potential, we do only update the property when there
48+ * actually is a hostname change, which makes it even less likely.
49 * rgerhards, 2013-10-28
50 */
51 static rsRetVal
52 GenerateLocalHostNameProperty(void)
53 {
54+ uchar *pszPrev;
55+ int lenPrev;
56 prop_t *hostnameNew;
57 uchar *pszName;
58 DEFiRet;
59
60- CHKiRet(prop.Construct(&hostnameNew));
61+ if(propLocalHostNameToDelete != NULL)
62+ prop.Destruct(&propLocalHostNameToDelete);
63+
64 if(LocalHostNameOverride == NULL) {
65 if(LocalHostName == NULL)
66 pszName = (uchar*) "[localhost]";
67@@ -411,11 +419,20 @@ GenerateLocalHostNameProperty(void)
68 pszName = LocalHostNameOverride;
69 }
70 DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName);
71- CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName)));
72- CHKiRet(prop.ConstructFinalize(hostnameNew));
73
74- propLocalHostName = hostnameNew;
75- /* inititional MEM LEAK for old value -- see function hdr comment! */
76+ if(propLocalHostName == NULL)
77+ pszPrev = (uchar*)""; /* make sure strcmp() below does not match */
78+ else
79+ prop.GetString(propLocalHostName, &pszPrev, &lenPrev);
80+
81+ if(ustrcmp(pszPrev, pszName)) {
82+ /* we need to update */
83+ CHKiRet(prop.Construct(&hostnameNew));
84+ CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName)));
85+ CHKiRet(prop.ConstructFinalize(hostnameNew));
86+ propLocalHostNameToDelete = propLocalHostName;
87+ propLocalHostName = hostnameNew;
88+ }
89
90 finalize_it:
91 RETiRet;
92@@ -678,6 +695,8 @@ BEGINObjClassExit(glbl, OBJ_IS_CORE_MODULE) /* class, version */
93 free(LocalHostNameOverride);
94 free(LocalFQDNName);
95 objRelease(prop, CORE_COMPONENT);
96+ if(propLocalHostNameToDelete != NULL)
97+ prop.Destruct(&propLocalHostNameToDelete);
98 DESTROY_ATOMIC_HELPER_MUT(mutTerminateInputs);
99 ENDObjClassExit(glbl)
100
101--
1021.7.9.5
103