aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-extended/rsyslog/rsyslog/0001-bugfix-potential-abort-during-HUP.patch
blob: 14e8b3f5abcabed7a01016fbad6906f6dedc76cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 9a775051f7373176c6e54bee1110965342dd41ad Mon Sep 17 00:00:00 2001
From: Rainer Gerhards <rgerhards@adiscon.com>
Date: Mon, 28 Oct 2013 12:56:02 +0100
Subject: [PATCH] bugfix: potential abort during HUP

This could happen when one of imklog, imzmq3, imkmsg, impstats,
imjournal, or imuxsock were under heavy load during a HUP.
closes: http://bugzilla.adiscon.com/show_bug.cgi?id=489
Thanks to Guy Rozendorn for reporting the problem and Peval Levhshin for
his analysis.

Upstream-Status: backport

Signed-off-by: Li Zhou <li.zhou@windriver.com>
---
 ChangeLog      |    6 ++++++
 runtime/glbl.c |   25 ++++++++++++++++++-------
 2 files changed, 24 insertions(+), 7 deletions(-)

Index: rsyslog-7.4.4/ChangeLog
===================================================================
--- rsyslog-7.4.4.orig/ChangeLog
+++ rsyslog-7.4.4/ChangeLog
@@ -1,5 +1,11 @@
 ---------------------------------------------------------------------------
 Version 7.4.4  [v7.4-stable] 2013-09-03
+- bugfix: potential abort during HUP
+  This could happen when one of imklog, imzmq3, imkmsg, impstats,
+  imjournal, or imuxsock were under heavy load during a HUP.
+  closes: http://bugzilla.adiscon.com/show_bug.cgi?id=489
+  Thanks to Guy Rozendorn for reporting the problem and Peval Levhshin for
+  his analysis.
 - better error messages in GuardTime signature provider
   Thanks to Ahto Truu for providing the patch.
 - make rsyslog use the new json-c pkgconfig file if available
Index: rsyslog-7.4.4/runtime/glbl.c
===================================================================
--- rsyslog-7.4.4.orig/runtime/glbl.c
+++ rsyslog-7.4.4/runtime/glbl.c
@@ -32,6 +32,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <pthread.h>
 #include <assert.h>
 
 #include "rsyslog.h"
@@ -379,17 +380,24 @@ GetLocalDomain(void)
 /* generate the local hostname property. This must be done after the hostname info
  * has been set as well as PreserveFQDN.
  * rgerhards, 2009-06-30
+ * NOTE: This function DELIBERATELY introduces a small memory leak in order to gain
+ * speed. Each time it is called when a property name already exists, a new one is
+ * allocated but the previous one is NOT freed. This is so that current readers can
+ * continue to use the previous name. Otherwise, we would need to use read/write locks
+ * to protect the update process. As this function is called extremely infrequently and
+ * the memory leak is very small, this is totally accessible. Think that otherwise we
+ * would need to place a read look each time the property is read, which is much more
+ * frequent (once per message for the modules that use this local hostname!).
+ * rgerhards, 2013-10-28
  */
 static rsRetVal
 GenerateLocalHostNameProperty(void)
 {
-	DEFiRet;
+	prop_t *hostnameNew;
 	uchar *pszName;
+	DEFiRet;
 
-	if(propLocalHostName != NULL)
-		prop.Destruct(&propLocalHostName);
-
-	CHKiRet(prop.Construct(&propLocalHostName));
+	CHKiRet(prop.Construct(&hostnameNew));
 	if(LocalHostNameOverride == NULL) {
 		if(LocalHostName == NULL)
 			pszName = (uchar*) "[localhost]";
@@ -403,8 +411,11 @@ GenerateLocalHostNameProperty(void)
 		pszName = LocalHostNameOverride;
 	}
 	DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName);
-	CHKiRet(prop.SetString(propLocalHostName, pszName, ustrlen(pszName)));
-	CHKiRet(prop.ConstructFinalize(propLocalHostName));
+	CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName)));
+	CHKiRet(prop.ConstructFinalize(hostnameNew));
+
+	propLocalHostName = hostnameNew;
+	/* inititional MEM LEAK for old value -- see function hdr comment! */
 
 finalize_it:
 	RETiRet;