summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-20 11:12:57 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-20 11:12:57 +0000
commitc34e69f9e36890af917f2cb9cdba01a8fa18d926 (patch)
tree0ebf90b1607d9d3c3cedeeca34cad70ba40c326a
parentc49042eb41a0ab0bba1f470f0457b379e6d6ad5e (diff)
downloadrsyslog-c34e69f9e36890af917f2cb9cdba01a8fa18d926.tar.gz
rsyslog-c34e69f9e36890af917f2cb9cdba01a8fa18d926.tar.xz
rsyslog-c34e69f9e36890af917f2cb9cdba01a8fa18d926.zip
bugfix: memory leak in cfsysline.c/doGetWord() fixed
-rw-r--r--cfsysline.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/cfsysline.c b/cfsysline.c
index 8731d64a..9cdba073 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -352,6 +352,12 @@ finalize_it:
* a pointer to a string which is to receive the option
* value. The returned string must be freed by the caller.
* rgerhards, 2007-09-07
+ * To facilitate multiple instances of the same command line
+ * directive, doGetWord() now checks if pVal is already a
+ * non-NULL pointer. If so, we assume it was created by a previous
+ * incarnation and is automatically freed. This happens only when
+ * no custom handler is defined. If it is, the customer handler
+ * must do the cleanup. -- rgerhards, 2007-12-20
*/
static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void *pVal)
{
@@ -380,7 +386,9 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void
/* we got the word, now set it */
if(pSetHdlr == NULL) {
/* we should set value directly to var */
- *((uchar**)pVal) = pNewVal;
+ if(pVal != NULL)
+ free(pVal); /* free previous entry */
+ *((uchar**)pVal) = pNewVal; /* set new one */
} else {
/* we set value via a set function */
CHKiRet(pSetHdlr(pVal, pNewVal));