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. --- syslogd.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'syslogd.c') 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 v1.2.3