From 3c7027687f8b64f424be085d0f238c2acf60e20a Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 17 Apr 2010 21:39:31 +0200 Subject: [PATCH] Fix logging api not cleaning up LogFileCtx mutex. --- src/tm-modules.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/tm-modules.c b/src/tm-modules.c index c82f687bc3..cbf079099f 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -55,9 +55,7 @@ LogFileCtx *LogFileNewCtx() } memset(lf_ctx, 0, sizeof(LogFileCtx)); - /* Ensure that it is unlocked */ SCMutexInit(&lf_ctx->fp_mutex,NULL); - SCMutexUnlock(&lf_ctx->fp_mutex); return lf_ctx; } @@ -68,25 +66,28 @@ LogFileCtx *LogFileNewCtx() * */ int LogFileFreeCtx(LogFileCtx *lf_ctx) { - int ret=0; + if (lf_ctx == NULL) { + SCReturnInt(0); + } - if(lf_ctx != NULL) + if (lf_ctx->fp != NULL) { - if (lf_ctx->fp != NULL) - { - SCMutexLock(&lf_ctx->fp_mutex); - fclose(lf_ctx->fp); - SCMutexUnlock(&lf_ctx->fp_mutex); - } - if (lf_ctx->prefix != NULL) - SCFree(lf_ctx->prefix); - if(lf_ctx->filename != NULL) - SCFree(lf_ctx->filename); - SCFree(lf_ctx); - ret=1; + SCMutexLock(&lf_ctx->fp_mutex); + fclose(lf_ctx->fp); + SCMutexUnlock(&lf_ctx->fp_mutex); } - return ret; + SCMutexDestroy(&lf_ctx->fp_mutex); + + if (lf_ctx->prefix != NULL) + SCFree(lf_ctx->prefix); + + if(lf_ctx->filename != NULL) + SCFree(lf_ctx->filename); + + SCFree(lf_ctx); + + SCReturnInt(1); } /** \brief register all unittests for the tm modules */