]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Flow: fix flow reference cnt issues
authorVictor Julien <victor@inliniac.net>
Sat, 8 Feb 2014 16:09:10 +0000 (17:09 +0100)
committerVictor Julien <victor@inliniac.net>
Sun, 9 Feb 2014 10:03:39 +0000 (11:03 +0100)
FlowReference stores the flow in the destination pointer and increases
the flow reference counter (use_cnt). This should only be called once
per destination pointer. The reference counter is decremented when
FlowDereference is called. Multiple FlowReference calls would lead to
multiple use_cnt bumps, while there would be only one FlowRereference.
This lead to a use_cnt that would never become 0, meaning the flow
would stay in the hash for the entire lifetime of the process.

The fix here is to check if the destination pointer is already set to
the flow. If so, we don't increase the reference counter.

As this is really a bug, this condition will lead to a BUG_ON if the
DEBUG_VALIDATION checking is enabled.

src/flow.h

index 5a44307b0fd7066204ab29fe05649b899ecbf54e..6ede7c6b2a57a84cc5421b3a3f967f733f2d257b 100644 (file)
@@ -521,8 +521,17 @@ static inline void FlowDecrUsecnt(Flow *f)
     (void) SC_ATOMIC_SUB(f->use_cnt, 1);
 }
 
+/** \brief Reference the flow, bumping the flows use_cnt
+ *  \note This should only be called once for a destination
+ *        pointer */
 static inline void FlowReference(Flow **d, Flow *f) {
     if (likely(f != NULL)) {
+#ifdef DEBUG_VALIDATION
+        BUG_ON(*d == f);
+#else
+        if (*d == f)
+            return;
+#endif
         FlowIncrUsecnt(f);
         *d = f;
     }