From fe0da1ef850dc9e93993f8332a87cbf815cea2f7 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 24 Jul 2007 05:59:06 +0000 Subject: fixed a small memory leak when HUPing syslogd. The allowed sender list now gets freed. thanks varmojfekoj to for the patch. --- ChangeLog | 2 ++ syslogd.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ChangeLog b/ChangeLog index 649f69fb..6b719d44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ Version 1.17.3 (rgerhards), 2007-07-2? - rsyslogd now checks on startup if it is capable to performa any work at all. If it cant, it complains and terminates thanks to Michel Samia for providing the patch! +- fixed a small memory leak when HUPing syslogd. The allowed sender + list now gets freed. thanks varmojfekoj to for the patch. --------------------------------------------------------------------------- Version 1.17.2 (rgerhards), 2007-07-23 - made the port part of the -r option optional. Needed for backward diff --git a/syslogd.c b/syslogd.c index 8dca5d28..c745b7ab 100644 --- a/syslogd.c +++ b/syslogd.c @@ -745,6 +745,24 @@ static rsRetVal AddAllowedSenderEntry(struct AllowedSenders **ppRoot, struct All return RS_RET_OK; } +/* function to clear the allowed sender structure in cases where + * it must be freed (occurs most often when HUPed. + * TODO: reconsider recursive implementation + */ +static void clearAllowedSenders (struct AllowedSenders *pAllow) { + if (pAllow != NULL) { + if (pAllow->pNext != NULL) + clearAllowedSenders (pAllow->pNext); + else { + if (F_ISSET(pAllow->allowedSender.flags, ADDR_NAME)) + free (pAllow->allowedSender.addr.HostWildcard); + else + free (pAllow->allowedSender.addr.NetAddr); + + free (pAllow); + } + } +} /* function to add an allowed sender to the allowed sender list. The * root of the list is caller-provided, so it can be used for all @@ -4133,6 +4151,21 @@ static void init() pDfltProgNameCmp = NULL; eDfltHostnameCmpMode = HN_NO_COMP; + if (restart) { + if (pAllowedSenders_UDP != NULL) { + clearAllowedSenders (pAllowedSenders_UDP); + pAllowedSenders_UDP = NULL; + } + + if (pAllowedSenders_TCP != NULL) { + clearAllowedSenders (pAllowedSenders_TCP); + pAllowedSenders_TCP = NULL; + } + } + + assert (pAllowedSenders_UDP == NULL && + pAllowedSenders_TCP == NULL ); + nextp = NULL; /* I was told by an IPv6 expert that calling getservbyname() seems to be * still valid, at least for the use case we have. So I re-enabled that -- cgit