summaryrefslogtreecommitdiffstats
path: root/cfsysline.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-20 11:15:38 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-20 11:15:38 +0000
commitee9b196128db5c6a30918c795f5adcdd2adaca45 (patch)
treea5f0ccc00834b1c83b73262c102cabeef85142d3 /cfsysline.c
parent76007a666e17d9456cd7e3864f4e23223fae94c3 (diff)
downloadrsyslog-ee9b196128db5c6a30918c795f5adcdd2adaca45.tar.gz
rsyslog-ee9b196128db5c6a30918c795f5adcdd2adaca45.tar.xz
rsyslog-ee9b196128db5c6a30918c795f5adcdd2adaca45.zip
bugfix: memory leak in cfsysline.c/doGetWord() fixed
Diffstat (limited to 'cfsysline.c')
-rw-r--r--cfsysline.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/cfsysline.c b/cfsysline.c
index 14f50927..cf5def0a 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -353,6 +353,13 @@ 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. I have checked and this was al also memory
+ * leak with some code. Obviously, not a large one. -- rgerhards, 2007-12-20
*/
static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void *pVal)
{
@@ -381,7 +388,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));