Fixing flow cleanup and ctx initialization

remotes/origin/master-1.0.x
Pablo Rincon 15 years ago committed by Victor Julien
parent eed0ef6e69
commit b931895901

@ -130,22 +130,18 @@ void TagRestartCtx() {
*/
void TagHashInit(DetectTagHostCtx *tag_ctx)
{
if (tag_ctx->tag_hash_table_ipv4 == NULL ||
tag_ctx->tag_hash_table_ipv6 == NULL) {
tag_ctx->tag_hash_table_ipv4 = HashListTableInit(TAG_HASH_SIZE, TagHashFunc, TagCompareFunc, TagFreeFunc);
if(tag_ctx->tag_hash_table_ipv4 == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Tag: Failed to initialize ipv4 dst hash table.");
exit(EXIT_FAILURE);
}
tag_ctx->tag_hash_table_ipv4 = HashListTableInit(TAG_HASH_SIZE, TagHashFunc, TagCompareFunc, TagFreeFunc);
if(tag_ctx->tag_hash_table_ipv4 == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Tag: Failed to initialize ipv4 dst hash table.");
exit(EXIT_FAILURE);
}
tag_ctx->tag_hash_table_ipv6 = HashListTableInit(TAG_HASH_SIZE, TagHashFunc, TagCompareFunc, TagFreeFunc);
if(tag_ctx->tag_hash_table_ipv6 == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Tag: Failed to initialize ipv4 src hash table.");
exit(EXIT_FAILURE);
}
tag_ctx->tag_hash_table_ipv6 = HashListTableInit(TAG_HASH_SIZE, TagHashFunc, TagCompareFunc, TagFreeFunc);
if(tag_ctx->tag_hash_table_ipv6 == NULL) {
SCLogError(SC_ERR_MEM_ALLOC,
"Tag: Failed to initialize ipv4 src hash table.");
exit(EXIT_FAILURE);
}
}

@ -988,6 +988,13 @@ void SigFree(Signature *s) {
sm = nsm;
}
sm = s->tmatch;
while (sm != NULL) {
nsm = sm->next;
SigMatchFree(sm);
sm = nsm;
}
DetectAddressHeadCleanup(&s->src);
DetectAddressHeadCleanup(&s->dst);

@ -110,6 +110,9 @@ int DetectTagFlowAdd(Packet *p, DetectTagDataEntry *tde) {
uint16_t num_tags = 0;
DetectTagDataEntry *iter = NULL;
if (p->flow == NULL)
return 1;
SCMutexLock(&p->flow->m);
if (p->flow->tag_list == NULL) {
@ -184,7 +187,7 @@ int DetectTagMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet *p, Si
if (td->direction == DETECT_TAG_DIR_SRC || td->direction == DETECT_TAG_DIR_DST) {
SCLogDebug("Tagging Host with sid %"PRIu32":%"PRIu32"", s->id, s->gid);
if (TagHashAddTag(tag_ctx, tde, p) == 1)
DetectTagDataEntryFree(tde);
SCFree(tde);
} else {
SCLogError(SC_ERR_INVALID_VALUE, "Error on direction of a tag keyword (not src nor dst)");
@ -194,7 +197,7 @@ int DetectTagMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet *p, Si
if (p->flow != NULL) {
/* If it already exists it will be updated */
if (DetectTagFlowAdd(p, tde) == 1)
DetectTagDataEntryFree(tde);
SCFree(tde);
} else {
SCLogDebug("No flow to append the session tag");
}
@ -384,7 +387,8 @@ void DetectTagDataEntryFree(void *ptr) {
DetectTagDataEntry *dte = (DetectTagDataEntry *)ptr;
if (dte->next != NULL)
DetectTagDataEntryFree(dte->next);
SCFree(ptr);
dte->next = NULL;
SCFree(dte);
}
}
@ -857,6 +861,8 @@ cleanup:
UTHFreePackets(p, 7);
if (det_ctx != NULL)
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
if (result == 1 && f.tag_list != NULL)
DetectTagDataListFree(f.tag_list);
if (de_ctx != NULL) {
SigGroupCleanup(de_ctx);

@ -90,6 +90,7 @@ typedef struct DetectTagDataEntryList_ {
DetectTagDataEntry *header_entry;
Address addr; /**< Var used to store dst or src addr */
uint8_t ipv; /**< IP Version */
SCMutex lock;
}DetectTagDataEntryList;
/* prototypes */

@ -541,6 +541,7 @@ end:
}
static int DetectTlsVersionTestDetect03(void) {
DetectEngineCtx *de_ctx = NULL;
int result = 0;
Flow f;
uint8_t tlsbuf1[] = { 0x16 };
@ -590,7 +591,7 @@ static int DetectTlsVersionTestDetect03(void) {
ssn.toserver_smsg_head = stream_msg;
ssn.toserver_smsg_tail = stream_msg;
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
goto end;
}

@ -80,6 +80,7 @@
(f)->alflags = 0; \
(f)->alproto = 0; \
DetectTagDataListFree((f)->tag_list); \
(f)->tag_list = NULL; \
} while(0)
#define FLOW_DESTROY(f) do { \
@ -97,6 +98,7 @@
(f)->alflags = 0; \
(f)->alproto = 0; \
DetectTagDataListFree((f)->tag_list); \
(f)->tag_list = NULL; \
} while(0)
Flow *FlowAlloc(void);

Loading…
Cancel
Save