Skip to content

Commit 1ef709c

Browse files
committed
bugfix: fixed a memory leak and potential abort condition
this could happen if multiple rulesets were used and some output batches contained messages belonging to more than one ruleset. fixes: http://bugzilla.adiscon.com/show_bug.cgi?id=226 fixes: http://bugzilla.adiscon.com/show_bug.cgi?id=218
1 parent f46fa5c commit 1ef709c

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

Diff for: ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---------------------------------------------------------------------------
22
Version 5.7.6 [V5-BETA] (rgerhards), 2011-02-??
3+
- bugfix: fixed a memory leak and potential abort condition
4+
this could happen if multiple rulesets were used and some output batches
5+
contained messages belonging to more than one ruleset.
6+
fixes: http://bugzilla.adiscon.com/show_bug.cgi?id=226
7+
fixes: http://bugzilla.adiscon.com/show_bug.cgi?id=218
38
- bugfix: memory leak when $RepeatedMsgReduction on was used
49
bug tracker: http://bugzilla.adiscon.com/show_bug.cgi?id=225
510
---------------------------------------------------------------------------

Diff for: runtime/batch.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,16 @@ batchIsValidElem(batch_t *pBatch, int i) {
136136
/* copy one batch element to another.
137137
* This creates a complete duplicate in those cases where
138138
* it is needed. Use duplication only when absolutely necessary!
139+
* Note that all working fields are reset to zeros. If that were
140+
* not done, we would have potential problems with invalid
141+
* or double pointer frees.
139142
* rgerhards, 2010-06-10
140143
*/
141144
static inline void
142145
batchCopyElem(batch_obj_t *pDest, batch_obj_t *pSrc) {
143-
memcpy(pDest, pSrc, sizeof(batch_obj_t));
146+
memset(pDest, 0, sizeof(batch_obj_t));
147+
pDest->pUsrp = pSrc->pUsrp;
148+
pDest->state = pSrc->state;
144149
}
145150

146151

@@ -171,6 +176,7 @@ batchFree(batch_t *pBatch) {
171176
static inline rsRetVal
172177
batchInit(batch_t *pBatch, int maxElem) {
173178
DEFiRet;
179+
pBatch->iDoneUpTo = 0;
174180
pBatch->maxElem = maxElem;
175181
CHKmalloc(pBatch->pElem = calloc((size_t)maxElem, sizeof(batch_obj_t)));
176182
// TODO: replace calloc by inidividual writes?

Diff for: runtime/ruleset.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -171,35 +171,40 @@ processBatchMultiRuleset(batch_t *pBatch)
171171
int i;
172172
int iStart; /* start index of partial batch */
173173
int iNew; /* index for new (temporary) batch */
174+
int bHaveUnprocessed; /* do we (still) have unprocessed entries? (loop term predicate) */
174175
DEFiRet;
175176

176-
CHKiRet(batchInit(&snglRuleBatch, pBatch->nElem));
177-
snglRuleBatch.pbShutdownImmediate = pBatch->pbShutdownImmediate;
178-
179-
while(1) { /* loop broken inside */
177+
do {
178+
bHaveUnprocessed = 0;
180179
/* search for first unprocessed element */
181180
for(iStart = 0 ; iStart < pBatch->nElem && pBatch->pElem[iStart].state == BATCH_STATE_DISC ; ++iStart)
182181
/* just search, no action */;
183-
184182
if(iStart == pBatch->nElem)
185-
FINALIZE; /* everything processed */
183+
break; /* everything processed */
186184

187185
/* prepare temporary batch */
186+
CHKiRet(batchInit(&snglRuleBatch, pBatch->nElem));
187+
snglRuleBatch.pbShutdownImmediate = pBatch->pbShutdownImmediate;
188188
currRuleset = batchElemGetRuleset(pBatch, iStart);
189189
iNew = 0;
190190
for(i = iStart ; i < pBatch->nElem ; ++i) {
191191
if(batchElemGetRuleset(pBatch, i) == currRuleset) {
192-
batchCopyElem(&(snglRuleBatch.pElem[iNew++]), &(pBatch->pElem[i]));
192+
/* for performance reasons, we copy only those members that we actually need */
193+
snglRuleBatch.pElem[iNew].pUsrp = pBatch->pElem[i].pUsrp;
194+
snglRuleBatch.pElem[iNew].state = pBatch->pElem[i].state;
195+
++iNew;
193196
/* We indicate the element also as done, so it will not be processed again */
194197
pBatch->pElem[i].state = BATCH_STATE_DISC;
198+
} else {
199+
bHaveUnprocessed = 1;
195200
}
196201
}
197202
snglRuleBatch.nElem = iNew; /* was left just right by the for loop */
198203
batchSetSingleRuleset(&snglRuleBatch, 1);
199204
/* process temp batch */
200205
processBatch(&snglRuleBatch);
201-
}
202-
batchFree(&snglRuleBatch);
206+
batchFree(&snglRuleBatch);
207+
} while(bHaveUnprocessed == 1);
203208

204209
finalize_it:
205210
RETiRet;

0 commit comments

Comments
 (0)