summaryrefslogtreecommitdiffstats
path: root/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-04-03 08:47:35 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-04-03 08:47:35 +0000
commit11461ad9c6de62556df79a35ff0c4902e2881f57 (patch)
treebcebd3205f213ddd4a9ae5218d40bbe0f16b965f /syslogd.c
parent2be9977a4db263400c8ba56c82e576b7da42cd86 (diff)
downloadrsyslog-11461ad9c6de62556df79a35ff0c4902e2881f57.tar.gz
rsyslog-11461ad9c6de62556df79a35ff0c4902e2881f57.tar.xz
rsyslog-11461ad9c6de62556df79a35ff0c4902e2881f57.zip
bugfix: memory leaks in script engine
Diffstat (limited to 'syslogd.c')
-rw-r--r--syslogd.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/syslogd.c b/syslogd.c
index 8c71f57d..b5554e5f 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -170,6 +170,7 @@ DEFobjCurrIf(datetime)
DEFobjCurrIf(conf)
DEFobjCurrIf(expr)
DEFobjCurrIf(vm)
+DEFobjCurrIf(var)
DEFobjCurrIf(module)
DEFobjCurrIf(errmsg)
DEFobjCurrIf(net) /* TODO: make go away! */
@@ -928,8 +929,8 @@ static rsRetVal shouldProcessThisMessage(selector_t *f, msg_t *pMsg, int *bProce
unsigned short pbMustBeFreed;
char *pszPropVal;
int bRet = 0;
- vm_t *pVM;
- var_t *pResult;
+ vm_t *pVM = NULL;
+ var_t *pResult = NULL;
assert(f != NULL);
assert(pMsg != NULL);
@@ -995,7 +996,7 @@ static rsRetVal shouldProcessThisMessage(selector_t *f, msg_t *pMsg, int *bProce
CHKiRet(vm.ExecProg(pVM, f->f_filterData.f_expr->pVmprg));
CHKiRet(vm.PopBoolFromStack(pVM, &pResult));
dbgprintf("result of expression evaluation: %lld\n", pResult->val.num);
- CHKiRet(vm.Destruct(&pVM));
+ /* VM is destructed on function exit */
bRet = (pResult->val.num) ? 1 : 0;
} else {
assert(f->f_filter_type == FILTER_PROP); /* assert() just in case... */
@@ -1051,6 +1052,12 @@ static rsRetVal shouldProcessThisMessage(selector_t *f, msg_t *pMsg, int *bProce
}
finalize_it:
+ /* destruct in any case, not just on error, but it makes error handling much easier */
+ if(pVM != NULL) {
+ var.Destruct(&pResult);
+ vm.Destruct(&pVM);
+ }
+
*bProcessMsg = bRet;
RETiRet;
}
@@ -2838,6 +2845,8 @@ InitGlobalClasses(void)
CHKiRet(objUse(errmsg, CORE_COMPONENT));
pErrObj = "module";
CHKiRet(objUse(module, CORE_COMPONENT));
+ pErrObj = "var";
+ CHKiRet(objUse(var, CORE_COMPONENT));
/* initialize and use classes. We must be very careful with the order of events. Some
* classes use others and if we do not initialize them in the right order, we may end