From 94e32990ee01bc7622909f40f0839bc4516cd56d Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 27 Mar 2008 14:58:53 +0000 Subject: fixed memory leaks in stream class and imfile --- plugins/imfile/imfile.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'plugins') diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c index a6e019d6..162cab9f 100644 --- a/plugins/imfile/imfile.c +++ b/plugins/imfile/imfile.c @@ -168,6 +168,17 @@ finalize_it: } +/* The following is a cancel cleanup handler for strmReadLine(). It is necessary in case + * strmReadLine() is cancelled while processing the stream. -- rgerhards, 2008-03-27 + */ +static void pollFileCancelCleanup(void *pArg) +{ + BEGINfunc; + cstr_t **ppCStr = (cstr_t**) pArg; + if(*ppCStr != NULL) + rsCStrDestruct(ppCStr); + ENDfunc; +} /* poll a file, need to check file rollover etc. open file if not open */ static rsRetVal pollFile(fileInfo_t *pThis, int *pbHadFileData) { @@ -180,6 +191,7 @@ static rsRetVal pollFile(fileInfo_t *pThis, int *pbHadFileData) CHKiRet(openFile(pThis)); /* open file */ } + pthread_cleanup_push(pollFileCancelCleanup, &pCStr); /* loop below will be exited when strmReadLine() returns EOF */ while(1) { CHKiRet(strmReadLine(pThis->pStrm, &pCStr)); @@ -187,6 +199,7 @@ static rsRetVal pollFile(fileInfo_t *pThis, int *pbHadFileData) CHKiRet(enqLine(pThis, pCStr)); /* process line */ rsCStrDestruct(&pCStr); /* discard string (must be done by us!) */ } + pthread_cleanup_pop(0); finalize_it: if(pCStr != NULL) { @@ -333,6 +346,9 @@ persistStrmState(fileInfo_t *pInfo) CHKiRet(strmDestruct(&psSF)); finalize_it: + if(psSF != NULL) + strmDestruct(&psSF); + RETiRet; } -- cgit