memory leak fixes

remotes/origin/master-1.0.x
Gurvinder Singh 17 years ago committed by Victor Julien
parent 66cc392177
commit 5c8d90afc8

@ -250,11 +250,6 @@ TmEcode AlertUnifiedAlertThreadDeinit(ThreadVars *t, void *data)
return TM_ECODE_OK; return TM_ECODE_OK;
error: error:
/* clear memory */
if (aun != NULL) {
memset(aun, 0, sizeof(AlertUnifiedAlertThread));
free(aun);
}
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
@ -296,6 +291,7 @@ LogFileCtx *AlertUnifiedAlertInitCtx(ConfNode *conf)
* */ * */
int AlertUnifiedAlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix) int AlertUnifiedAlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
{ {
int ret = 0;
char *filename = NULL; char *filename = NULL;
if (file_ctx->filename != NULL) if (file_ctx->filename != NULL)
filename = file_ctx->filename; filename = file_ctx->filename;
@ -319,10 +315,11 @@ int AlertUnifiedAlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
if (file_ctx->fp == NULL) { if (file_ctx->fp == NULL) {
SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename, SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename,
strerror(errno)); strerror(errno));
return -1; ret = -1;
} }
if (filename != NULL)
return 0; free(filename);
return ret;
} }
#ifdef UNITTESTS #ifdef UNITTESTS

@ -312,6 +312,7 @@ LogFileCtx *AlertUnifiedLogInitCtx(ConfNode *conf)
* */ * */
int AlertUnifiedLogOpenFileCtx(LogFileCtx *file_ctx, const char *prefix) int AlertUnifiedLogOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
{ {
int ret = 0;
char *filename = NULL; char *filename = NULL;
if (file_ctx->filename != NULL) if (file_ctx->filename != NULL)
filename = file_ctx->filename; filename = file_ctx->filename;
@ -335,10 +336,11 @@ int AlertUnifiedLogOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
if (file_ctx->fp == NULL) { if (file_ctx->fp == NULL) {
SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename, SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename,
strerror(errno)); strerror(errno));
return -1; ret = -1;
} }
if (filename != NULL)
return 0; free(filename);
return ret;
} }
#ifdef UNITTESTS #ifdef UNITTESTS

@ -536,11 +536,6 @@ TmEcode Unified2AlertThreadDeinit(ThreadVars *t, void *data)
return TM_ECODE_OK; return TM_ECODE_OK;
error: error:
/* clear memory */
if (aun != NULL) {
memset(aun, 0, sizeof(Unified2AlertThread));
free(aun);
}
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
@ -583,6 +578,7 @@ LogFileCtx *Unified2AlertInitCtx(ConfNode *conf)
* */ * */
int Unified2AlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix) int Unified2AlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
{ {
int ret = 0;
char *filename = NULL; char *filename = NULL;
if (file_ctx->filename != NULL) if (file_ctx->filename != NULL)
filename = file_ctx->filename; filename = file_ctx->filename;
@ -606,10 +602,11 @@ int Unified2AlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
if (file_ctx->fp == NULL) { if (file_ctx->fp == NULL) {
SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename, SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename,
strerror(errno)); strerror(errno));
return -1; ret = -1;
} }
if (filename != NULL)
return 0; free(filename);
return ret;
} }

@ -70,11 +70,18 @@ void AlpProtoInit(AlpProtoDetectCtx *ctx) {
ctx->toclient.id = 0; ctx->toclient.id = 0;
} }
void AlpProtoDestroy(AlpProtoDetectCtx *ctx) { void AlpProtoTestDestroy(AlpProtoDetectCtx *ctx) {
mpm_table[ctx->toserver.mpm_ctx.mpm_type].DestroyCtx(&ctx->toserver.mpm_ctx); mpm_table[ctx->toserver.mpm_ctx.mpm_type].DestroyCtx(&ctx->toserver.mpm_ctx);
mpm_table[ctx->toclient.mpm_ctx.mpm_type].DestroyCtx(&ctx->toclient.mpm_ctx); mpm_table[ctx->toclient.mpm_ctx.mpm_type].DestroyCtx(&ctx->toclient.mpm_ctx);
} }
void AlpProtoDestroy() {
SCEnter();
mpm_table[alp_proto_ctx.toserver.mpm_ctx.mpm_type].DestroyCtx(&alp_proto_ctx.toserver.mpm_ctx);
mpm_table[alp_proto_ctx.toclient.mpm_ctx.mpm_type].DestroyCtx(&alp_proto_ctx.toclient.mpm_ctx);
SCReturn;
}
/** \brief Add a proto detection string to the detection ctx. /** \brief Add a proto detection string to the detection ctx.
* \param ctx The detection ctx * \param ctx The detection ctx
* \param ip_proto The IP proto (TCP, UDP, etc) * \param ip_proto The IP proto (TCP, UDP, etc)
@ -129,6 +136,20 @@ void AlpProtoFinalizeThread(AlpProtoDetectCtx *ctx, AlpProtoDetectThreadCtx *tct
} }
} }
void AlpProtoDeFinalize2Thread(AlpProtoDetectThreadCtx *tctx) {
if (alp_proto_ctx.toclient.id > 0) {
mpm_table[alp_proto_ctx.toclient.mpm_ctx.mpm_type].DestroyThreadCtx
(&alp_proto_ctx.toclient.mpm_ctx, &tctx->toclient.mpm_ctx);
/* XXX GS any idea why it is invalid free ?*/
//PmqFree(&tctx->toclient.pmq);
}
if (alp_proto_ctx.toserver.id > 0) {
mpm_table[alp_proto_ctx.toserver.mpm_ctx.mpm_type].DestroyThreadCtx
(&alp_proto_ctx.toserver.mpm_ctx, &tctx->toserver.mpm_ctx);
//PmqFree(&tctx->toserver.pmq);
}
}
/** \brief to be called by ReassemblyThreadInit /** \brief to be called by ReassemblyThreadInit
* \todo this is a hack, we need a proper place to store the global ctx */ * \todo this is a hack, we need a proper place to store the global ctx */
void AlpProtoFinalize2Thread(AlpProtoDetectThreadCtx *tctx) { void AlpProtoFinalize2Thread(AlpProtoDetectThreadCtx *tctx) {
@ -468,7 +489,7 @@ int AlpDetectTest01(void) {
} }
free(buf); free(buf);
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -502,7 +523,7 @@ int AlpDetectTest02(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -547,7 +568,7 @@ int AlpDetectTest03(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -580,7 +601,7 @@ int AlpDetectTest04(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -626,7 +647,7 @@ int AlpDetectTest05(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -671,7 +692,7 @@ int AlpDetectTest06(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -704,7 +725,7 @@ int AlpDetectTest07(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -748,7 +769,7 @@ int AlpDetectTest08(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -789,7 +810,7 @@ int AlpDetectTest09(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }
@ -826,7 +847,7 @@ int AlpDetectTest10(void) {
r = 0; r = 0;
} }
AlpProtoDestroy(&ctx); AlpProtoTestDestroy(&ctx);
return r; return r;
} }

@ -22,6 +22,8 @@ void AppLayerDetectProtoThreadSpawn(void);
void AlpDetectRegisterTests(void); void AlpDetectRegisterTests(void);
void AlpProtoFinalize2Thread(AlpProtoDetectThreadCtx *); void AlpProtoFinalize2Thread(AlpProtoDetectThreadCtx *);
void AlpProtoDeFinalize2Thread (AlpProtoDetectThreadCtx *);
void AlpProtoDestroy(void);
#endif /* __APP_LAYER_DETECT_PROTO_H__ */ #endif /* __APP_LAYER_DETECT_PROTO_H__ */

@ -325,6 +325,7 @@ static int SCPerfParseTBCounterInterval(SCPerfCounter *pc, char *interval)
(pc->type_q->minutes * 60) + pc->type_q->seconds); (pc->type_q->minutes * 60) + pc->type_q->seconds);
TimeGet(&pc->type_q->ts); TimeGet(&pc->type_q->ts);
free(regex);
return 0; return 0;
error: error:

@ -542,10 +542,10 @@ int SigParse(DetectEngineCtx *de_ctx, Signature *s, char *sigstr, uint8_t addrs_
if (basics != NULL) { if (basics != NULL) {
int i = 0; int i = 0;
while (basics[i] != NULL) { while (basics[i] != NULL) {
//free(basics[i]); free(basics[i]);
i++; i++;
} }
//free(basics); free(basics);
} }
SCReturnInt(ret); SCReturnInt(ret);

@ -176,6 +176,7 @@ void StreamTcpReassembleFree(char quiet)
TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void) TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void)
{ {
SCEnter();
TcpReassemblyThreadCtx *ra_ctx = malloc(sizeof(TcpReassemblyThreadCtx)); TcpReassemblyThreadCtx *ra_ctx = malloc(sizeof(TcpReassemblyThreadCtx));
if (ra_ctx == NULL) { if (ra_ctx == NULL) {
return NULL; return NULL;
@ -185,17 +186,19 @@ TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void)
ra_ctx->stream_q = StreamMsgQueueGetNew(); ra_ctx->stream_q = StreamMsgQueueGetNew();
AlpProtoFinalize2Thread(&ra_ctx->dp_ctx); AlpProtoFinalize2Thread(&ra_ctx->dp_ctx);
return ra_ctx; SCReturnPtr(ra_ctx, "TcpReassemblyThreadCtx");
} }
void StreamTcpReassembleFreeThreadCtx(TcpReassemblyThreadCtx *ra_ctx) void StreamTcpReassembleFreeThreadCtx(TcpReassemblyThreadCtx *ra_ctx)
{ {
SCEnter();
if (ra_ctx->stream_q != NULL) if (ra_ctx->stream_q != NULL)
StreamMsgQueueFree(ra_ctx->stream_q); StreamMsgQueueFree(ra_ctx->stream_q);
ra_ctx->stream_q = NULL; ra_ctx->stream_q = NULL;
AlpProtoDeFinalize2Thread(&ra_ctx->dp_ctx);
free(ra_ctx); free(ra_ctx);
SCReturn;
} }
void PrintList2(TcpSegment *seg) void PrintList2(TcpSegment *seg)

@ -42,6 +42,7 @@ int StreamTcpReassembleInit(char);
void StreamTcpReassembleFree(char); void StreamTcpReassembleFree(char);
void StreamTcpReassembleRegisterTests(void); void StreamTcpReassembleRegisterTests(void);
TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void); TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(void);
void StreamTcpReassembleFreeThreadCtx(TcpReassemblyThreadCtx *);
int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *); int StreamTcpReassembleProcessAppLayer(TcpReassemblyThreadCtx *);
void StreamTcpCreateTestPacket(uint8_t *, uint8_t, uint8_t, uint8_t); void StreamTcpCreateTestPacket(uint8_t *, uint8_t, uint8_t, uint8_t);

@ -2434,9 +2434,10 @@ TmEcode StreamTcp (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data) TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
{ {
SCEnter();
StreamTcpThread *stt = malloc(sizeof(StreamTcpThread)); StreamTcpThread *stt = malloc(sizeof(StreamTcpThread));
if (stt == NULL) { if (stt == NULL) {
return TM_ECODE_FAILED; SCReturnInt(TM_ECODE_FAILED);
} }
memset(stt, 0, sizeof(StreamTcpThread)); memset(stt, 0, sizeof(StreamTcpThread));
@ -2451,15 +2452,16 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
/* init reassembly ctx */ /* init reassembly ctx */
stt->ra_ctx = StreamTcpReassembleInitThreadCtx(); stt->ra_ctx = StreamTcpReassembleInitThreadCtx();
if (stt->ra_ctx == NULL) if (stt->ra_ctx == NULL)
return TM_ECODE_FAILED; SCReturnInt(TM_ECODE_FAILED);
SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p", SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p",
stt, stt->ra_ctx); stt, stt->ra_ctx);
return TM_ECODE_OK; SCReturnInt(TM_ECODE_OK);
} }
TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data) TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data)
{ {
SCEnter();
StreamTcpThread *stt = (StreamTcpThread *)data; StreamTcpThread *stt = (StreamTcpThread *)data;
if (stt == NULL) { if (stt == NULL) {
return TM_ECODE_OK; return TM_ECODE_OK;
@ -2468,13 +2470,13 @@ TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data)
/* XXX */ /* XXX */
/* free reassembly ctx */ /* free reassembly ctx */
StreamTcpReassembleFreeThreadCtx(stt->ra_ctx);
/* clear memory */ /* clear memory */
memset(stt, 0, sizeof(StreamTcpThread)); memset(stt, 0, sizeof(StreamTcpThread));
free(stt); free(stt);
return TM_ECODE_OK; SCReturnInt(TM_ECODE_OK);
} }
void StreamTcpExitPrintStats(ThreadVars *tv, void *data) void StreamTcpExitPrintStats(ThreadVars *tv, void *data)

@ -757,6 +757,7 @@ int main(int argc, char **argv)
SigGroupCleanup(de_ctx); SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx); SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
AlpProtoDestroy();
RunModeShutDown(); RunModeShutDown();
OutputDeregisterAll(); OutputDeregisterAll();

@ -126,8 +126,12 @@ static inline int SCClassConfInitContext(DetectEngineCtx *de_ctx)
/** /**
* \brief Releases resources used by the Classification Config API. * \brief Releases resources used by the Classification Config API.
*/ */
static void SCClassConfDeInitContext(void) static void SCClassConfDeInitContext(DetectEngineCtx *de_ctx)
{ {
if (de_ctx->class_conf_ht != NULL) {
HashTableFree(de_ctx->class_conf_ht);
de_ctx->class_conf_ht = NULL;
}
fclose(fd); fclose(fd);
default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH; default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
fd = NULL; fd = NULL;
@ -447,7 +451,7 @@ void SCClassConfLoadClassficationConfigFile(DetectEngineCtx *de_ctx)
} }
SCClassConfParseFile(de_ctx); SCClassConfParseFile(de_ctx);
SCClassConfDeInitContext(); SCClassConfDeInitContext(de_ctx);
return; return;
} }

Loading…
Cancel
Save