summaryrefslogtreecommitdiffstats
path: root/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-04-03 08:48:25 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-04-03 08:48:25 +0000
commitf1c9f5da133f4c6c8b52c5948cc0f61e32c210f1 (patch)
tree0fa2a1cb256578ea1492724d0b771630e2ecf762 /syslogd.c
parentbaf9a567599ada3da4b14f913fa4b10d0aabf03c (diff)
downloadrsyslog-f1c9f5da133f4c6c8b52c5948cc0f61e32c210f1.zip
rsyslog-f1c9f5da133f4c6c8b52c5948cc0f61e32c210f1.tar.gz
rsyslog-f1c9f5da133f4c6c8b52c5948cc0f61e32c210f1.tar.xz
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 1c31fb6..4bed94c 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)
/* 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
* up with an invalid call. The most important thing that can happen is that an error
+ pErrObj = "var";
+ CHKiRet(objUse(var, CORE_COMPONENT));
* is detected and needs to be logged, wich in turn requires a broader number of classes
* to be available. The solution is that we take care in the order of calls AND use a
* class immediately after it is initialized. And, of course, we load those classes