diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | syslogd.c | 5 | ||||
-rw-r--r-- | template.c | 51 | ||||
-rw-r--r-- | template.h | 1 |
4 files changed, 59 insertions, 1 deletions
@@ -5,6 +5,9 @@ Version 1.17.1 (RGer), 2007-07-?? - fixed bug that caused $AllowedSenders to handle IPv6 scopes incorrectly; also fixed but that could grabble $AllowedSender wildcards. Thanks to mildew@gmail.com for the patch +- minor code cleanup - thanks to Peter Vrabec for the patch +- fixed minimal memory leak on HUP (caused by templates) + thanks to varmojfekoj <varmojfekoj@gmail.com> for the patch --------------------------------------------------------------------------- Version 1.17.0 (RGer), 2007-07-17 - added $RepeatedLineReduction config parameter @@ -7913,6 +7913,9 @@ static void init() /* Reflect the deletion of the Files linked list. */ Files = NULL; } + + dprintf("Clearing templates.\n"); + tplDeleteNew(); f = NULL; nextp = NULL; @@ -10233,7 +10236,7 @@ int main(int argc, char **argv) pTmp = template_StdUsrMsgFmt; tplAddLine(" StdUsrMsgFmt", &pTmp); pTmp = template_StdDBFmt; - tplAddLine(" StdDBFmt", &pTmp); + tplLastStaticInit(tplAddLine(" StdDBFmt", &pTmp)); /* prepare emergency logging system */ @@ -21,6 +21,7 @@ static struct template *tplRoot = NULL; /* the root of the template list */ static struct template *tplLast = NULL; /* points to the last element of the template list */ +static struct template *tplLastStatic = NULL; /* last static element of the template list */ /* Constructs a template entry object. Returns pointer to it * or NULL (if it fails). Pointer to associated template list entry @@ -629,6 +630,56 @@ void tplDeleteAll(void) } } +/* Destroy all templates obtained from conf file + * preserving hadcoded ones. This is called from init(). + */ +void tplDeleteNew(void) +{ + struct template *pTpl, *pTplDel; + struct templateEntry *pTpe, *pTpeDel; + + if(tplRoot == NULL || tplLastStatic == NULL) + return; + + pTpl = tplLastStatic->pNext; + tplLastStatic->pNext = NULL; + tplLast = tplLastStatic; + while(pTpl != NULL) { + /* dprintf("Delete Template: Name='%s'\n ", pTpl->pszName == NULL? "NULL" : pTpl->pszName);*/ + pTpe = pTpl->pEntryRoot; + while(pTpe != NULL) { + pTpeDel = pTpe; + pTpe = pTpe->pNext; + /*dprintf("\tDelete Entry(%x): type %d, ", (unsigned) pTpeDel, pTpeDel->eEntryType);*/ + switch(pTpeDel->eEntryType) { + case UNDEFINED: + /*dprintf("(UNDEFINED)");*/ + break; + case CONSTANT: + /*dprintf("(CONSTANT), value: '%s'", + pTpeDel->data.constant.pConstant);*/ + free(pTpeDel->data.constant.pConstant); + break; + case FIELD: + /*dprintf("(FIELD), value: '%s'", pTpeDel->data.field.pPropRepl);*/ + free(pTpeDel->data.field.pPropRepl); + break; + } + /*dprintf("\n");*/ + free(pTpeDel); + } + pTplDel = pTpl; + pTpl = pTpl->pNext; + if(pTplDel->pszName != NULL) + free(pTplDel->pszName); + free(pTplDel); + } +} + +/* Store the pointer to the last hardcoded teplate */ +void tplLastStaticInit(struct template *tpl) { + tplLastStatic = tpl; +} /* Print the template structure. This is more or less a * debug or test aid, but anyhow I think it's worth it... @@ -67,6 +67,7 @@ struct template *tplAddLine(char* pName, unsigned char** pRestOfConfLine); struct template *tplFind(char *pName, int iLenName); int tplGetEntryCount(struct template *pTpl); void tplDeleteAll(void); +void tplDeleteNew(void); void tplPrintList(void); /* |