diff --git a/src/decode.h b/src/decode.h index 50036192ba..4b097a2123 100644 --- a/src/decode.h +++ b/src/decode.h @@ -627,6 +627,16 @@ typedef struct DecodeThreadVars_ #endif +/* \todo there is another copy of this same macro inside flow-util.h. The + * reason we have this duplicate is because we couldn't solve endless + * header files cross-reference. */ +#define FlowDeReference(src_f_ptr) do { \ + if (*(src_f_ptr) != NULL) { \ + FlowDecrUsecnt(*(src_f_ptr)); \ + *(src_f_ptr) = NULL; \ + } \ + } while (0) + /** * \brief Recycle a packet structure for reuse. * \todo the mutex destroy & init is necessary because of the memset, reconsider @@ -641,7 +651,7 @@ typedef struct DecodeThreadVars_ (p)->flags = 0; \ (p)->flowflags = 0; \ (p)->pkt_src = 0; \ - (p)->flow = NULL; \ + FlowDeReference(&((p)->flow)); \ (p)->ts.tv_sec = 0; \ (p)->ts.tv_usec = 0; \ (p)->datalink = 0; \ diff --git a/src/flow-util.h b/src/flow-util.h index 21768bd327..c6e15b3e21 100644 --- a/src/flow-util.h +++ b/src/flow-util.h @@ -134,6 +134,9 @@ } \ } while (0) +/* \todo there is another copy of this same macro inside decode.h. The reason + * we have this duplicate is because we couldn't solve endless header + * files cross-reference. */ #define FlowDeReference(src_f_ptr) do { \ if (*(src_f_ptr) != NULL) { \ FlowDecrUsecnt(*(src_f_ptr)); \ diff --git a/src/stream-tcp.c b/src/stream-tcp.c index dbc6ab85c5..8c9d6e5b41 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -190,7 +190,7 @@ void StreamTcpSessionClear(void *ssnptr) SCLogDebug("returning smsg %p to pool", smsg); smsg->next = NULL; smsg->prev = NULL; - smsg->flow = NULL; + FlowDeReference(&smsg->flow); StreamMsgReturnToPool(smsg); smsg = smsg_next; } @@ -202,7 +202,7 @@ void StreamTcpSessionClear(void *ssnptr) SCLogDebug("returning smsg %p to pool", smsg); smsg->next = NULL; smsg->prev = NULL; - smsg->flow = NULL; + FlowDeReference(&smsg->flow); StreamMsgReturnToPool(smsg); smsg = smsg_next; } @@ -289,7 +289,7 @@ void StreamTcpSessionPoolCleanup(void *s) SCLogDebug("returning smsg %p to pool", smsg); smsg->next = NULL; smsg->prev = NULL; - smsg->flow = NULL; + FlowDeReference(&smsg->flow); StreamMsgReturnToPool(smsg); smsg = smsg_next; } @@ -301,7 +301,7 @@ void StreamTcpSessionPoolCleanup(void *s) SCLogDebug("returning smsg %p to pool", smsg); smsg->next = NULL; smsg->prev = NULL; - smsg->flow = NULL; + FlowDeReference(&smsg->flow); StreamMsgReturnToPool(smsg); smsg = smsg_next; } diff --git a/src/stream.c b/src/stream.c index d6f8a9a79c..6bb43dfea7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -30,6 +30,7 @@ #include "util-pool.h" #include "util-debug.h" #include "stream-tcp.h" +#include "flow-util.h" #ifdef DEBUG static SCMutex stream_pool_memuse_mutex; @@ -215,7 +216,7 @@ void StreamMsgReturnListToPool(void *list) { SCLogDebug("returning smsg %p to pool", smsg); smsg->next = NULL; smsg->prev = NULL; - smsg->flow = NULL; + FlowDeReference(&smsg->flow); StreamMsgReturnToPool(smsg); smsg = smsg_next; } diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 84a7f6a021..9310f88075 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -36,6 +36,7 @@ #include "threads.h" #include "threadvars.h" #include "flow.h" +#include "flow-util.h" #include "stream.h" #include "stream-tcp-reassemble.h" @@ -242,13 +243,13 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p) SCLogDebug("tunnel stuff done, move on (proot %d)", proot); } - FlowDecrUsecnt(p->flow); + FlowDeReference(&p->flow); /* we're done with the tunnel root now as well */ if (proot == 1) { SCLogDebug("getting rid of root pkt... alloc'd %s", p->root->flags & PKT_ALLOC ? "true" : "false"); - FlowDecrUsecnt(p->root->flow); + FlowDeReference(&p->root->flow); /* if p->root uses extended data, free them */ if (p->root->ReleaseData) { if (p->root->ReleaseData(t, p->root) == TM_ECODE_FAILED) {