memroy leaks fixes in detection module, app layer and counters

remotes/origin/master-1.0.x
Gurvinder Singh 16 years ago committed by Victor Julien
parent 18954a2c4c
commit cda664a8c4

@ -240,6 +240,7 @@ void AlpProtoDestroy() {
SCEnter(); SCEnter();
mpm_table[alp_proto_ctx.toserver.mpm_ctx.mpm_type].DestroyCtx(&alp_proto_ctx.toserver.mpm_ctx); 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); mpm_table[alp_proto_ctx.toclient.mpm_ctx.mpm_type].DestroyCtx(&alp_proto_ctx.toclient.mpm_ctx);
MpmPatternIdTableFreeHash(alp_proto_ctx.mpm_pattern_id_store);
SCReturn; SCReturn;
} }
@ -266,13 +267,12 @@ void AlpProtoDeFinalize2Thread(AlpProtoDetectThreadCtx *tctx) {
if (alp_proto_ctx.toclient.id > 0) { if (alp_proto_ctx.toclient.id > 0) {
mpm_table[alp_proto_ctx.toclient.mpm_ctx.mpm_type].DestroyThreadCtx mpm_table[alp_proto_ctx.toclient.mpm_ctx.mpm_type].DestroyThreadCtx
(&alp_proto_ctx.toclient.mpm_ctx, &tctx->toclient.mpm_ctx); (&alp_proto_ctx.toclient.mpm_ctx, &tctx->toclient.mpm_ctx);
/* XXX GS any idea why it is invalid free ?*/ PmqFree(&tctx->toclient.pmq);
//PmqFree(&tctx->toclient.pmq);
} }
if (alp_proto_ctx.toserver.id > 0) { if (alp_proto_ctx.toserver.id > 0) {
mpm_table[alp_proto_ctx.toserver.mpm_ctx.mpm_type].DestroyThreadCtx mpm_table[alp_proto_ctx.toserver.mpm_ctx.mpm_type].DestroyThreadCtx
(&alp_proto_ctx.toserver.mpm_ctx, &tctx->toserver.mpm_ctx); (&alp_proto_ctx.toserver.mpm_ctx, &tctx->toserver.mpm_ctx);
//PmqFree(&tctx->toserver.pmq); PmqFree(&tctx->toserver.pmq);
} }
} }

@ -337,6 +337,10 @@ static void SCPerfInitOPCtx(void)
*/ */
static void SCPerfReleaseOPCtx() static void SCPerfReleaseOPCtx()
{ {
SCPerfClubTMInst *pctmi = NULL;
SCPerfClubTMInst *temp = NULL;
pctmi = sc_perf_op_ctx->pctmi;
if (sc_perf_op_ctx != NULL) { if (sc_perf_op_ctx != NULL) {
if (sc_perf_op_ctx->fp != NULL) if (sc_perf_op_ctx->fp != NULL)
fclose(sc_perf_op_ctx->fp); fclose(sc_perf_op_ctx->fp);
@ -344,14 +348,16 @@ static void SCPerfReleaseOPCtx()
if (sc_perf_op_ctx->file != NULL) if (sc_perf_op_ctx->file != NULL)
SCFree(sc_perf_op_ctx->file); SCFree(sc_perf_op_ctx->file);
if (sc_perf_op_ctx->pctmi != NULL) { while (pctmi != NULL) {
if (sc_perf_op_ctx->pctmi->tm_name != NULL) if (pctmi->tm_name != NULL)
SCFree(sc_perf_op_ctx->pctmi->tm_name); SCFree(pctmi->tm_name);
if (sc_perf_op_ctx->pctmi->head != NULL) if (pctmi->head != NULL)
SCFree(sc_perf_op_ctx->pctmi->head); SCFree(pctmi->head);
SCFree(sc_perf_op_ctx->pctmi); temp = pctmi->next;
SCFree(pctmi);
pctmi = temp;
} }
SCFree(sc_perf_op_ctx); SCFree(sc_perf_op_ctx);
@ -494,7 +500,8 @@ static int SCPerfParseTBCounterInterval(SCPerfCounter *pc, char *interval)
pcre_extra *regex_study = NULL; pcre_extra *regex_study = NULL;
int opts = 0; int opts = 0;
const char *ep = NULL; const char *ep = NULL;
const char *str_ptr = NULL; const char *str_ptr1 = NULL;
const char *str_ptr2 = NULL;
int eo = 0; int eo = 0;
int ret = 0; int ret = 0;
int res = 0; int res = 0;
@ -522,20 +529,20 @@ static int SCPerfParseTBCounterInterval(SCPerfCounter *pc, char *interval)
} }
for (i = 1; i < ret; i += 2) { for (i = 1; i < ret; i += 2) {
res = pcre_get_substring((char *)interval, ov, 30, i, &str_ptr); res = pcre_get_substring((char *)interval, ov, 30, i, &str_ptr1);
if (res < 0) { if (res < 0) {
SCLogInfo("SCPerfParseTBCounterInterval:pcre_get_substring failed"); SCLogInfo("SCPerfParseTBCounterInterval:pcre_get_substring failed");
goto error; goto error;
} }
temp_value = atoi(str_ptr); temp_value = atoi(str_ptr1);
res = pcre_get_substring((char *)interval, ov, 30, i + 1, &str_ptr); res = pcre_get_substring((char *)interval, ov, 30, i + 1, &str_ptr2);
if (res < 0) { if (res < 0) {
SCLogInfo("SCPerfParseTBCounterInterval:pcre_get_substring failed"); SCLogInfo("SCPerfParseTBCounterInterval:pcre_get_substring failed");
goto error; goto error;
} }
switch (*str_ptr) { switch (*str_ptr2) {
case 'h': case 'h':
if (temp_value < 0 || temp_value > 24) { if (temp_value < 0 || temp_value > 24) {
SCLogInfo("Invalid timebased counter interval"); SCLogInfo("Invalid timebased counter interval");
@ -571,10 +578,14 @@ static int SCPerfParseTBCounterInterval(SCPerfCounter *pc, char *interval)
pc->type_q->total_secs = ((pc->type_q->hours * 60 * 60) + pc->type_q->total_secs = ((pc->type_q->hours * 60 * 60) +
(pc->type_q->minutes * 60) + pc->type_q->seconds); (pc->type_q->minutes * 60) + pc->type_q->seconds);
if (str_ptr1 != NULL) SCFree((char *)str_ptr1);
if (str_ptr2 != NULL) SCFree((char *)str_ptr2);
SCFree(regex); SCFree(regex);
return 0; return 0;
error: error:
if (str_ptr1 != NULL) SCFree((char *)str_ptr1);
if (str_ptr2 != NULL) SCFree((char *)str_ptr2);
return -1; return -1;
} }

@ -180,9 +180,11 @@ static int DetectClasstypeSetup(DetectEngineCtx *de_ctx, Signature *s, char *raw
if (s->prio == -1) if (s->prio == -1)
s->prio = ct->priority; s->prio = ct->priority;
pcre_free_substring(parsed_ct_name);
return 0; return 0;
error: error:
if (parsed_ct_name != NULL) pcre_free_substring(parsed_ct_name);
return -1; return -1;
} }

@ -449,15 +449,19 @@ error:
* \param cd pointer to DetectCotentData * \param cd pointer to DetectCotentData
*/ */
void DetectContentFree(void *ptr) { void DetectContentFree(void *ptr) {
SCEnter();
DetectContentData *cd = (DetectContentData *)ptr; DetectContentData *cd = (DetectContentData *)ptr;
if (cd == NULL) if (cd == NULL)
return; SCReturn;
if (cd->content != NULL) if (cd->content != NULL)
SCFree(cd->content); SCFree(cd->content);
BoyerMooreCtxDeInit(cd->bm_ctx);
SCFree(cd); SCFree(cd);
SCReturn;
} }
#ifdef UNITTESTS /* UNITTESTS */ #ifdef UNITTESTS /* UNITTESTS */

@ -64,14 +64,15 @@
* \retval IPOnlyCIDRItem address of the new instance * \retval IPOnlyCIDRItem address of the new instance
*/ */
IPOnlyCIDRItem *IPOnlyCIDRItemNew() { IPOnlyCIDRItem *IPOnlyCIDRItemNew() {
SCEnter();
IPOnlyCIDRItem *item = NULL; IPOnlyCIDRItem *item = NULL;
item = SCMalloc(sizeof(IPOnlyCIDRItem)); item = SCMalloc(sizeof(IPOnlyCIDRItem));
if (item == NULL) if (item == NULL)
return NULL; SCReturnPtr(NULL, "NULL");
memset(item, 0, sizeof(IPOnlyCIDRItem)); memset(item, 0, sizeof(IPOnlyCIDRItem));
return item; SCReturnPtr(item, "IPOnlyCIDRItem");
} }
/** /**
@ -128,7 +129,7 @@ IPOnlyCIDRItem *IPOnlyCIDRItemInsert(IPOnlyCIDRItem *head,
/* The first element */ /* The first element */
if (head == NULL) { if (head == NULL) {
SCLogDebug("Head is NULL"); SCLogDebug("Head is NULL to insert item (%p)",item);
return item; return item;
} }
@ -137,7 +138,7 @@ IPOnlyCIDRItem *IPOnlyCIDRItemInsert(IPOnlyCIDRItem *head,
return head; return head;
} }
SCLogDebug("Inserting %u ", item->netmask); SCLogDebug("Inserting item(%p)->netmast %u head %p", item, item->netmask, head);
prev = item; prev = item;
while (prev != NULL) { while (prev != NULL) {
@ -158,12 +159,15 @@ IPOnlyCIDRItem *IPOnlyCIDRItemInsert(IPOnlyCIDRItem *head,
* \param tmphead Pointer to the list * \param tmphead Pointer to the list
*/ */
void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead) { void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead) {
SCEnter();
uint32_t i = 0; uint32_t i = 0;
IPOnlyCIDRItem *it, *next = NULL; IPOnlyCIDRItem *it, *next = NULL;
if (tmphead == NULL) if (tmphead == NULL) {
SCLogDebug("temphead is NULL");
return; return;
}
it = tmphead; it = tmphead;
next = it->next; next = it->next;
@ -171,12 +175,13 @@ void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead) {
while (it != NULL) { while (it != NULL) {
i++; i++;
SCFree(it); SCFree(it);
SCLogDebug("Item %"PRIu32" removed", i); SCLogDebug("Item(%p) %"PRIu32" removed\n", it, i);
it = next; it = next;
if (next != NULL) if (next != NULL)
next = next->next; next = next->next;
} }
SCReturn;
} }
/** /**
@ -860,6 +865,9 @@ void IPOnlyPrint(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx) {
*/ */
void IPOnlyDeinit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx) { void IPOnlyDeinit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx) {
if (io_ctx == NULL)
return;
if (io_ctx->tree_ipv4src != NULL) if (io_ctx->tree_ipv4src != NULL)
SCRadixReleaseRadixTree(io_ctx->tree_ipv4src); SCRadixReleaseRadixTree(io_ctx->tree_ipv4src);
@ -874,6 +882,7 @@ void IPOnlyDeinit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx) {
if (io_ctx->sig_init_array) if (io_ctx->sig_init_array)
SCFree(io_ctx->sig_init_array); SCFree(io_ctx->sig_init_array);
io_ctx->sig_init_array = NULL; io_ctx->sig_init_array = NULL;
} }

@ -962,9 +962,11 @@ static uint32_t MpmPatternIdHashFunc(HashTable *ht, void *p, uint16_t len) {
/** \brief free a MpmPatternIdTableElmt */ /** \brief free a MpmPatternIdTableElmt */
static void MpmPatternIdTableElmtFree(void *e) { static void MpmPatternIdTableElmtFree(void *e) {
SCEnter();
MpmPatternIdTableElmt *c = (MpmPatternIdTableElmt *)e; MpmPatternIdTableElmt *c = (MpmPatternIdTableElmt *)e;
free(c->pattern); SCFree(c->pattern);
free(e); SCFree(c);
SCReturn;
} }
/** \brief alloc initialize the MpmPatternIdHash */ /** \brief alloc initialize the MpmPatternIdHash */
@ -1048,7 +1050,7 @@ uint32_t DetectContentGetId(MpmPatternIdStore *ht, DetectContentData *co) {
} }
if (e != NULL) if (e != NULL)
free(e); MpmPatternIdTableElmtFree(e);
SCReturnUInt(id); SCReturnUInt(id);
} }
@ -1097,7 +1099,7 @@ uint32_t DetectUricontentGetId(MpmPatternIdStore *ht, DetectUricontentData *co)
} }
if (e != NULL) if (e != NULL)
free(e); MpmPatternIdTableElmtFree(e);
SCReturnUInt(id); SCReturnUInt(id);
} }

@ -1460,7 +1460,7 @@ void DetectPortFreeFunc(void *p) {
*/ */
int DetectPortDpHashInit(DetectEngineCtx *de_ctx) { int DetectPortDpHashInit(DetectEngineCtx *de_ctx) {
de_ctx->dport_hash_table = HashListTableInit(PORT_HASH_SIZE, de_ctx->dport_hash_table = HashListTableInit(PORT_HASH_SIZE,
DetectPortHashFunc, DetectPortCompareFunc, NULL); DetectPortHashFunc, DetectPortCompareFunc, DetectPortFreeFunc);
if (de_ctx->dport_hash_table == NULL) if (de_ctx->dport_hash_table == NULL)
goto error; goto error;
@ -1525,7 +1525,7 @@ DetectPort *DetectPortDpHashLookup(DetectEngineCtx *de_ctx, DetectPort *p) {
*/ */
int DetectPortSpHashInit(DetectEngineCtx *de_ctx) { int DetectPortSpHashInit(DetectEngineCtx *de_ctx) {
de_ctx->sport_hash_table = HashListTableInit(PORT_HASH_SIZE, de_ctx->sport_hash_table = HashListTableInit(PORT_HASH_SIZE,
DetectPortHashFunc, DetectPortCompareFunc, NULL); DetectPortHashFunc, DetectPortCompareFunc, DetectPortFreeFunc);
if (de_ctx->sport_hash_table == NULL) if (de_ctx->sport_hash_table == NULL)
goto error; goto error;

@ -904,7 +904,9 @@ void SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
{ {
SCSigOrderFunc *funcs = NULL; SCSigOrderFunc *funcs = NULL;
SCSigSignatureWrapper *sigw = NULL; SCSigSignatureWrapper *sigw = NULL;
SCSigSignatureWrapper *prev = NULL;
void *temp = NULL; void *temp = NULL;
uint8_t i;
/* clean the memory alloted to the signature ordering funcs */ /* clean the memory alloted to the signature ordering funcs */
funcs = de_ctx->sc_sig_order_funcs; funcs = de_ctx->sc_sig_order_funcs;
@ -918,9 +920,15 @@ void SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
/* clean the memory alloted to the signature wrappers */ /* clean the memory alloted to the signature wrappers */
sigw = de_ctx->sc_sig_sig_wrapper; sigw = de_ctx->sc_sig_sig_wrapper;
while (sigw != NULL) { while (sigw != NULL) {
temp = sigw; prev = sigw;
sigw = sigw->next; sigw = sigw->next;
SCFree(temp); for (i = 0; i < SC_RADIX_USER_DATA_MAX; i++) {
if (prev->user[i] != NULL) {
SCFree(prev->user[i]);
}
}
SCFree(prev->user);
SCFree(prev);
} }
de_ctx->sc_sig_sig_wrapper = NULL; de_ctx->sc_sig_sig_wrapper = NULL;

@ -535,6 +535,11 @@ TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data) {
PatternMatchThreadDestroy(&det_ctx->mtc, det_ctx->de_ctx->mpm_matcher); PatternMatchThreadDestroy(&det_ctx->mtc, det_ctx->de_ctx->mpm_matcher);
PatternMatchThreadDestroy(&det_ctx->mtcu, det_ctx->de_ctx->mpm_matcher); PatternMatchThreadDestroy(&det_ctx->mtcu, det_ctx->de_ctx->mpm_matcher);
PmqFree(&det_ctx->pmq);
if (det_ctx->de_state_sig_array != NULL)
SCFree(det_ctx->de_state_sig_array);
SCFree(det_ctx); SCFree(det_ctx);
return TM_ECODE_OK; return TM_ECODE_OK;

@ -52,6 +52,7 @@ int DetectHttpClientBodyMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
SigMatch *m); SigMatch *m);
int DetectHttpClientBodySetup(DetectEngineCtx *, Signature *, char *); int DetectHttpClientBodySetup(DetectEngineCtx *, Signature *, char *);
void DetectHttpClientBodyRegisterTests(void); void DetectHttpClientBodyRegisterTests(void);
void DetectHttpClientBodyFree(void *);
/** /**
* \brief Registers the keyword handlers for the "http_client_body" keyword. * \brief Registers the keyword handlers for the "http_client_body" keyword.
@ -63,7 +64,7 @@ void DetectHttpClientBodyRegister(void)
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].AppLayerMatch = DetectHttpClientBodyMatch; sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].AppLayerMatch = DetectHttpClientBodyMatch;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].alproto = ALPROTO_HTTP; sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].alproto = ALPROTO_HTTP;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Setup = DetectHttpClientBodySetup; sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Setup = DetectHttpClientBodySetup;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Free = NULL; sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Free = DetectHttpClientBodyFree;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].RegisterTests = DetectHttpClientBodyRegisterTests; sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].RegisterTests = DetectHttpClientBodyRegisterTests;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].flags |= SIGMATCH_PAYLOAD ; sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].flags |= SIGMATCH_PAYLOAD ;
@ -248,15 +249,34 @@ int DetectHttpClientBodySetup(DetectEngineCtx *de_ctx, Signature *s, char *arg)
return 0; return 0;
error: error:
if (hcbd != NULL) { if (hcbd != NULL)
DetectHttpClientBodyFree(hcbd);
if(nm != NULL)
SCFree(nm);
return -1;
}
/**
* \brief The function to free the http_client_body data.
*
* \param ptr Pointer to the http_client_body.
*/
void DetectHttpClientBodyFree(void *ptr)
{
SCEnter();
DetectHttpClientBodyData *hcbd = (DetectHttpClientBodyData *)ptr;
if (hcbd == NULL)
SCReturn;
if (hcbd->content != NULL) if (hcbd->content != NULL)
SCFree(hcbd->content); SCFree(hcbd->content);
BoyerMooreCtxDeInit(hcbd->bm_ctx);
SCFree(hcbd); SCFree(hcbd);
}
if(nm != NULL)
SCFree(sm);
return -1; SCReturn;
} }
/************************************Unittests*********************************/ /************************************Unittests*********************************/

@ -54,6 +54,7 @@ int DetectHttpCookieMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
SigMatch *m); SigMatch *m);
static int DetectHttpCookieSetup (DetectEngineCtx *, Signature *, char *); static int DetectHttpCookieSetup (DetectEngineCtx *, Signature *, char *);
void DetectHttpCookieRegisterTests(void); void DetectHttpCookieRegisterTests(void);
void DetectHttpCookieFree(void *);
/** /**
* \brief Registration function for keyword: http_cookie * \brief Registration function for keyword: http_cookie
@ -64,7 +65,7 @@ void DetectHttpCookieRegister (void) {
sigmatch_table[DETECT_AL_HTTP_COOKIE].AppLayerMatch = DetectHttpCookieMatch; sigmatch_table[DETECT_AL_HTTP_COOKIE].AppLayerMatch = DetectHttpCookieMatch;
sigmatch_table[DETECT_AL_HTTP_COOKIE].alproto = ALPROTO_HTTP; sigmatch_table[DETECT_AL_HTTP_COOKIE].alproto = ALPROTO_HTTP;
sigmatch_table[DETECT_AL_HTTP_COOKIE].Setup = DetectHttpCookieSetup; sigmatch_table[DETECT_AL_HTTP_COOKIE].Setup = DetectHttpCookieSetup;
sigmatch_table[DETECT_AL_HTTP_COOKIE].Free = NULL; sigmatch_table[DETECT_AL_HTTP_COOKIE].Free = DetectHttpCookieFree;
sigmatch_table[DETECT_AL_HTTP_COOKIE].RegisterTests = DetectHttpCookieRegisterTests; sigmatch_table[DETECT_AL_HTTP_COOKIE].RegisterTests = DetectHttpCookieRegisterTests;
sigmatch_table[DETECT_AL_HTTP_COOKIE].flags |= SIGMATCH_PAYLOAD; sigmatch_table[DETECT_AL_HTTP_COOKIE].flags |= SIGMATCH_PAYLOAD;
@ -164,6 +165,21 @@ end:
SCReturnInt(ret); SCReturnInt(ret);
} }
/**
* \brief this function clears the memory of http_cookie modifier keyword
*
* \param ptr Pointer to the Detection Cookie data
*/
void DetectHttpCookieFree(void *ptr)
{
DetectHttpCookieData *hcd = (DetectHttpCookieData *)ptr;
if (hcd == NULL)
return;
if (hcd->data != NULL)
SCFree(hcd->data);
SCFree(hcd);
}
/** /**
* \brief this function setups the http_cookie modifier keyword used in the rule * \brief this function setups the http_cookie modifier keyword used in the rule
* *
@ -244,6 +260,7 @@ static int DetectHttpCookieSetup (DetectEngineCtx *de_ctx, Signature *s, char *s
/* free the old content sigmatch, the content pattern memory /* free the old content sigmatch, the content pattern memory
* is taken over by the new sigmatch */ * is taken over by the new sigmatch */
BoyerMooreCtxDeInit(((DetectContentData *)pm->ctx)->bm_ctx);
SCFree(pm->ctx); SCFree(pm->ctx);
SCFree(pm); SCFree(pm);
@ -258,11 +275,7 @@ static int DetectHttpCookieSetup (DetectEngineCtx *de_ctx, Signature *s, char *s
s->alproto = ALPROTO_HTTP; s->alproto = ALPROTO_HTTP;
return 0; return 0;
error: error:
if (hd != NULL) { if (hd != NULL) DetectHttpCookieFree(hd);
if (hd->data != NULL)
SCFree(hd->data);
SCFree(hd);
}
if(sm !=NULL) SCFree(sm); if(sm !=NULL) SCFree(sm);
return -1; return -1;
} }

@ -53,6 +53,7 @@ int DetectHttpHeaderMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
SigMatch *m); SigMatch *m);
int DetectHttpHeaderSetup(DetectEngineCtx *, Signature *, char *); int DetectHttpHeaderSetup(DetectEngineCtx *, Signature *, char *);
void DetectHttpHeaderRegisterTests(void); void DetectHttpHeaderRegisterTests(void);
void DetectHttpHeaderFree(void *);
/** /**
* \brief Registers the keyword handlers for the "http_header" keyword. * \brief Registers the keyword handlers for the "http_header" keyword.
@ -64,7 +65,7 @@ void DetectHttpHeaderRegister(void)
sigmatch_table[DETECT_AL_HTTP_HEADER].AppLayerMatch = DetectHttpHeaderMatch; sigmatch_table[DETECT_AL_HTTP_HEADER].AppLayerMatch = DetectHttpHeaderMatch;
sigmatch_table[DETECT_AL_HTTP_HEADER].alproto = ALPROTO_HTTP; sigmatch_table[DETECT_AL_HTTP_HEADER].alproto = ALPROTO_HTTP;
sigmatch_table[DETECT_AL_HTTP_HEADER].Setup = DetectHttpHeaderSetup; sigmatch_table[DETECT_AL_HTTP_HEADER].Setup = DetectHttpHeaderSetup;
sigmatch_table[DETECT_AL_HTTP_HEADER].Free = NULL; sigmatch_table[DETECT_AL_HTTP_HEADER].Free = DetectHttpHeaderFree;
sigmatch_table[DETECT_AL_HTTP_HEADER].RegisterTests = DetectHttpHeaderRegisterTests; sigmatch_table[DETECT_AL_HTTP_HEADER].RegisterTests = DetectHttpHeaderRegisterTests;
sigmatch_table[DETECT_AL_HTTP_HEADER].flags |= SIGMATCH_PAYLOAD ; sigmatch_table[DETECT_AL_HTTP_HEADER].flags |= SIGMATCH_PAYLOAD ;
@ -141,6 +142,21 @@ int DetectHttpHeaderMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
SCReturnInt(result); SCReturnInt(result);
} }
/**
* \brief this function clears the memory of http_header modifier keyword
*
* \param ptr Pointer to the Detection Header Data
*/
void DetectHttpHeaderFree(void *ptr)
{
DetectHttpHeaderData *hd = (DetectHttpHeaderData *)ptr;
if (hd == NULL)
return;
if (hd->content != NULL)
SCFree(hd->content);
SCFree(hd);
}
/** /**
* \brief The setup function for the http_header keyword for a signature. * \brief The setup function for the http_header keyword for a signature.
* *
@ -226,6 +242,7 @@ int DetectHttpHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, char *arg)
/* free the old content sigmatch, the content pattern memory /* free the old content sigmatch, the content pattern memory
* is taken over by the new sigmatch */ * is taken over by the new sigmatch */
BoyerMooreCtxDeInit(((DetectContentData *)sm->ctx)->bm_ctx);
SCFree(sm->ctx); SCFree(sm->ctx);
SCFree(sm); SCFree(sm);
@ -238,11 +255,8 @@ int DetectHttpHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, char *arg)
return 0; return 0;
error: error:
if (hcbd != NULL) { if (hcbd != NULL)
if (hcbd->content != NULL) DetectHttpHeaderFree(hcbd);
SCFree(hcbd->content);
SCFree(hcbd);
}
if(nm != NULL) if(nm != NULL)
SCFree(sm); SCFree(sm);

@ -149,7 +149,6 @@ static int DetectHttpMethodSetup(DetectEngineCtx *de_ctx, Signature *s, char *st
{ {
SCEnter(); SCEnter();
DetectHttpMethodData *data = NULL; DetectHttpMethodData *data = NULL;
SigMatch *sm = NULL;
bstr *method; bstr *method;
/** new sig match to replace previous content */ /** new sig match to replace previous content */
SigMatch *nm = NULL; SigMatch *nm = NULL;
@ -216,6 +215,7 @@ static int DetectHttpMethodSetup(DetectEngineCtx *de_ctx, Signature *s, char *st
/* free the old content sigmatch, the memory for the pattern /* free the old content sigmatch, the memory for the pattern
* is taken over by our new sigmatch */ * is taken over by our new sigmatch */
BoyerMooreCtxDeInit(((DetectContentData *)pm->ctx)->bm_ctx);
SCFree(pm->ctx); SCFree(pm->ctx);
SCFree(pm); SCFree(pm);
@ -232,7 +232,8 @@ static int DetectHttpMethodSetup(DetectEngineCtx *de_ctx, Signature *s, char *st
error: error:
if (data != NULL) DetectHttpMethodFree(data); if (data != NULL) DetectHttpMethodFree(data);
if (sm != NULL) SCFree(sm); if (nm->ctx != NULL) DetectHttpMethodFree(nm);
if (nm != NULL) SCFree(nm);
SCReturnInt(-1); SCReturnInt(-1);
} }

@ -436,7 +436,7 @@ static int SigParseOptions(DetectEngineCtx *de_ctx, Signature *s, char *optstr)
if (optvalue) pcre_free_substring(optvalue); if (optvalue) pcre_free_substring(optvalue);
if (optstr) SCFree(optstr); if (optstr) SCFree(optstr);
//if (optmore) pcre_free_substring(optmore); //if (optmore) pcre_free_substring(optmore);
if (arr != NULL) SCFree(arr); if (arr != NULL) pcre_free_substring_list(arr);
return SigParseOptions(de_ctx, s, optmore); return SigParseOptions(de_ctx, s, optmore);
} }
@ -444,7 +444,7 @@ static int SigParseOptions(DetectEngineCtx *de_ctx, Signature *s, char *optstr)
if (optvalue) pcre_free_substring(optvalue); if (optvalue) pcre_free_substring(optvalue);
if (optmore) pcre_free_substring(optmore); if (optmore) pcre_free_substring(optmore);
if (optstr) SCFree(optstr); if (optstr) SCFree(optstr);
if (arr != NULL) SCFree(arr); if (arr != NULL) pcre_free_substring_list(arr);
return 0; return 0;
error: error:
@ -452,7 +452,7 @@ error:
if (optvalue) pcre_free_substring(optvalue); if (optvalue) pcre_free_substring(optvalue);
if (optmore) pcre_free_substring(optmore); if (optmore) pcre_free_substring(optmore);
if (optstr) SCFree(optstr); if (optstr) SCFree(optstr);
if (arr != NULL) SCFree(arr); if (arr != NULL) pcre_free_substring_list(arr);
return -1; return -1;
} }
@ -783,6 +783,14 @@ void SigFree(Signature *s) {
if (s == NULL) if (s == NULL)
return; return;
/* XXX GS there seems to be a bug in the IPOnlyCIDR list, which causes
system abort. */
/*if (s->CidrDst != NULL)
IPOnlyCIDRListFree(s->CidrDst);
if (s->CidrSrc != NULL)
IPOnlyCIDRListFree(s->CidrSrc);*/
SigMatch *sm = s->match, *nsm; SigMatch *sm = s->match, *nsm;
while (sm != NULL) { while (sm != NULL) {
nsm = sm->next; nsm = sm->next;
@ -796,6 +804,21 @@ void SigFree(Signature *s) {
SigMatchFree(sm); SigMatchFree(sm);
sm = nsm; sm = nsm;
} }
sm = s->umatch;
while (sm != NULL) {
nsm = sm->next;
SigMatchFree(sm);
sm = nsm;
}
sm = s->amatch;
while (sm != NULL) {
nsm = sm->next;
SigMatchFree(sm);
sm = nsm;
}
DetectAddressHeadCleanup(&s->src); DetectAddressHeadCleanup(&s->src);
DetectAddressHeadCleanup(&s->dst); DetectAddressHeadCleanup(&s->dst);

@ -59,6 +59,7 @@ void HttpUriRegisterTests(void);
int DetectAppLayerUricontentMatch (ThreadVars *, DetectEngineThreadCtx *, int DetectAppLayerUricontentMatch (ThreadVars *, DetectEngineThreadCtx *,
Flow *, uint8_t , void *, Flow *, uint8_t , void *,
Signature *, SigMatch *); Signature *, SigMatch *);
void DetectUricontentFree(void *);
/** /**
* \brief Registration function for uricontent: keyword * \brief Registration function for uricontent: keyword
@ -69,7 +70,7 @@ void DetectUricontentRegister (void)
sigmatch_table[DETECT_URICONTENT].AppLayerMatch = NULL; sigmatch_table[DETECT_URICONTENT].AppLayerMatch = NULL;
sigmatch_table[DETECT_URICONTENT].Match = NULL; sigmatch_table[DETECT_URICONTENT].Match = NULL;
sigmatch_table[DETECT_URICONTENT].Setup = DetectUricontentSetup; sigmatch_table[DETECT_URICONTENT].Setup = DetectUricontentSetup;
sigmatch_table[DETECT_URICONTENT].Free = NULL; sigmatch_table[DETECT_URICONTENT].Free = DetectUricontentFree;
sigmatch_table[DETECT_URICONTENT].RegisterTests = HttpUriRegisterTests; sigmatch_table[DETECT_URICONTENT].RegisterTests = HttpUriRegisterTests;
sigmatch_table[DETECT_URICONTENT].alproto = ALPROTO_HTTP; sigmatch_table[DETECT_URICONTENT].alproto = ALPROTO_HTTP;
@ -85,6 +86,27 @@ uint32_t DetectUricontentMaxId(DetectEngineCtx *de_ctx)
return MpmPatternIdStoreGetMaxId(de_ctx->mpm_pattern_id_store); return MpmPatternIdStoreGetMaxId(de_ctx->mpm_pattern_id_store);
} }
/**
* \brief this function will Free memory associated with DetectUricontentData
*
* \param cd pointer to DetectUricotentData
*/
void DetectUricontentFree(void *ptr) {
SCEnter();
DetectUricontentData *cd = (DetectUricontentData *)ptr;
if (cd == NULL)
SCReturn;
if (cd->uricontent != NULL)
SCFree(cd->uricontent);
BoyerMooreCtxDeInit(cd->bm_ctx);
SCFree(cd);
SCReturn;
}
/** /**
* \brief Helper function to print a DetectContentData * \brief Helper function to print a DetectContentData
*/ */
@ -342,6 +364,7 @@ int DetectUricontentSetup (DetectEngineCtx *de_ctx, Signature *s, char *contents
error: error:
if (cd) SCFree(cd); if (cd) SCFree(cd);
if (sm != NULL) SCFree(sm);
SCReturnInt(-1); SCReturnInt(-1);
} }

@ -538,6 +538,11 @@ static inline SCLogOPIfaceCtx *SCLogInitFileOPIface(const char *file,
{ {
SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx(); SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx();
if (iface_ctx == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitFileOPIface. Exiting...");
exit(EXIT_FAILURE);
}
iface_ctx->iface = SC_LOG_OP_IFACE_FILE; iface_ctx->iface = SC_LOG_OP_IFACE_FILE;
if (file != NULL && if (file != NULL &&
@ -577,11 +582,10 @@ static inline SCLogOPIfaceCtx *SCLogInitConsoleOPIface(const char *log_format,
{ {
SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx(); SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx();
if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) { if (iface_ctx == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitConsoleOPIface. Exiting..."); SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitConsoleOPIface. Exiting...");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(iface_ctx, 0, sizeof(SCLogOPIfaceCtx));
iface_ctx->iface = SC_LOG_OP_IFACE_CONSOLE; iface_ctx->iface = SC_LOG_OP_IFACE_CONSOLE;
@ -632,11 +636,10 @@ static inline SCLogOPIfaceCtx *SCLogInitSyslogOPIface(int facility,
{ {
SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx(); SCLogOPIfaceCtx *iface_ctx = SCLogAllocLogOPIfaceCtx();
if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) { if ( iface_ctx == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitSyslogOPIface. Exiting..."); SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitSyslogOPIface. Exiting...");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(iface_ctx, 0, sizeof(SCLogOPIfaceCtx));
iface_ctx->iface = SC_LOG_OP_IFACE_SYSLOG; iface_ctx->iface = SC_LOG_OP_IFACE_SYSLOG;
@ -1171,6 +1174,7 @@ void SCLogLoadConfig(void)
SCLogInitLogModule(sc_lid); SCLogInitLogModule(sc_lid);
//exit(1); //exit(1);
/* \todo Can we free sc_lid now? */ /* \todo Can we free sc_lid now? */
if (sc_lid != NULL) SCFree(sc_lid);
} }
/** /**

@ -304,6 +304,9 @@ int SCHInfoAddHostOSInfo(char *host_os, char *host_os_ip_range, int is_ipv4)
SCHInfoAddHostOSInfo(host_os, ip_str_rem, is_ipv4); SCHInfoAddHostOSInfo(host_os, ip_str_rem, is_ipv4);
} }
if (ip_str != NULL) SCFree(ip_str);
if (ipv4_addr != NULL) SCFree(ipv4_addr);
if (ipv6_addr != NULL) SCFree(ipv6_addr);
return *user_data; return *user_data;
} }

@ -150,12 +150,12 @@ static void B2gHashFree(MpmCtx *mpm_ctx, B2gHashItem *hi) {
if (hi == NULL) if (hi == NULL)
return; return;
B2gHashItem *t = hi->nxt;
B2gHashFree(mpm_ctx, t);
mpm_ctx->memory_cnt--; mpm_ctx->memory_cnt--;
mpm_ctx->memory_size -= sizeof(B2gHashItem); mpm_ctx->memory_size -= sizeof(B2gHashItem);
B2gHashItem *t = hi->nxt;
SCFree(hi); SCFree(hi);
B2gHashFree(mpm_ctx, t);
} }
static inline void memcpy_tolower(uint8_t *d, uint8_t *s, uint16_t len) { static inline void memcpy_tolower(uint8_t *d, uint8_t *s, uint16_t len) {

@ -149,7 +149,6 @@ void PmqFree(PatternMatcherQueue *pmq) {
return; return;
PmqCleanup(pmq); PmqCleanup(pmq);
SCFree(pmq);
} }
/** /**

@ -85,6 +85,24 @@ BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint32_t needle_len) {
return new; return new;
} }
/**
* \brief Free the memory allocated to Booyer More context.
*
* \param bmCtx pointer to the Context for the pattern
*/
void BoyerMooreCtxDeInit(BmCtx *bmctx)
{
SCEnter();
if (bmctx == NULL)
SCReturn;
if (bmctx->bmGs != NULL)
SCFree(bmctx->bmGs);
SCFree(bmctx);
SCReturn;
}
/** /**
* \brief Array setup function for bad characters that split the pattern * \brief Array setup function for bad characters that split the pattern
* Remember that the result array should be the length of ALPHABET_SIZE * Remember that the result array should be the length of ALPHABET_SIZE

@ -48,6 +48,6 @@ void PreBmBcNocase(const uint8_t *x, int32_t m, int32_t *bmBc);
void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff); void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff);
void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs); void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs);
uint8_t *BoyerMooreNocase(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc); uint8_t *BoyerMooreNocase(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc);
void BoyerMooreCtxDeInit(BmCtx *);
#endif /* __UTIL_SPM_BM__ */ #endif /* __UTIL_SPM_BM__ */

Loading…
Cancel
Save