summaryrefslogtreecommitdiffstats
path: root/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-03-20 09:31:05 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-03-20 09:31:05 +0000
commit06ffec1c3f9e566993d372cc686c8ae7307c5de0 (patch)
tree5bbc3fe7bec322540318ec2d2a564c5f09c48b71 /syslogd.c
parenta00b06ea93a91f784cf8b41fc493e589a14a80b4 (diff)
downloadrsyslog-06ffec1c3f9e566993d372cc686c8ae7307c5de0.tar.gz
rsyslog-06ffec1c3f9e566993d372cc686c8ae7307c5de0.tar.xz
rsyslog-06ffec1c3f9e566993d372cc686c8ae7307c5de0.zip
bugfix: fixed some minor memory leaks
Diffstat (limited to 'syslogd.c')
-rw-r--r--syslogd.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/syslogd.c b/syslogd.c
index 454083d4..9e7f80cb 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -1872,6 +1872,23 @@ static void doDie(int sig)
}
+/* This function frees all dynamically allocated memory for program termination.
+ * It must be called only immediately before exit(). It is primarily an aid
+ * for memory debuggers, which prevents cluttered outupt.
+ * rgerhards, 2008-03-20
+ */
+static void
+freeAllDynMemForTermination(void)
+{
+ if(pszWorkDir != NULL)
+ free(pszWorkDir);
+ if(pszMainMsgQFName != NULL)
+ free(pszMainMsgQFName);
+ if(pModDir != NULL)
+ free(pModDir);
+}
+
+
/* die() is called when the program shall end. This typically only occurs
* during sigterm or during the initialization.
* As die() is intended to shutdown rsyslogd, it is
@@ -1947,9 +1964,6 @@ die(int sig)
*/
unregCfSysLineHdlrs();
- /* clean up auxiliary data */
- if(pModDir != NULL)
- free(pModDir);
legacyOptsFree();
/* terminate the remaining classes */
@@ -1971,6 +1985,12 @@ die(int sig)
/* dbgClassExit MUST be the last one, because it de-inits the debug system */
dbgClassExit();
+ /* free all remaining memory blocks - this is not absolutely necessary, but helps
+ * us keep memory debugger logs clean and this is in aid in developing. It doesn't
+ * cost much time, so we do it always. -- rgerhards, 2008-03-20
+ */
+ freeAllDynMemForTermination();
+ /* NO CODE HERE - feeelAllDynMemForTermination() must be the last thing before exit()! */
exit(0); /* "good" exit, this is the terminator function for rsyslog [die()] */
}