]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packet handling: fix release function
authorEric Leblond <eric@regit.org>
Thu, 10 Apr 2014 11:11:34 +0000 (13:11 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 18 Apr 2014 05:58:54 +0000 (07:58 +0200)
Extended data were freed before the release function was called.
The result was that, in AF_PACKET IPS mode, the release function
was only sending void data because it the content of the extended
data is the content of the packet.

This patch updates the code to have the freeing of extended data
done in the cleaning function for a packet which is called by the
release function. This improves consistency of the code and fixes
the bug.

src/decode.c
src/tmqh-packetpool.c

index 1aa964c5f1be7b82ee6a7f1760fc2f31ffaf85da..17ca90b3bc6ab92acdcd1e9023a1b874afd14ea4 100644 (file)
@@ -82,6 +82,19 @@ int DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
     return TM_ECODE_OK;
 }
 
+static inline void PacketFreeExtData(Packet *p)
+{
+    /* if p uses extended data, free them */
+    if (p->ext_pkt) {
+        if (!(p->flags & PKT_ZERO_COPY)) {
+            SCFree(p->ext_pkt);
+        }
+        p->ext_pkt = NULL;
+    }
+}
+
+
+
 /**
  * \brief Return a malloced packet.
  */
@@ -140,6 +153,7 @@ Packet *PacketGetFromAlloc(void)
  */
 void PacketFreeOrRelease(Packet *p)
 {
+    PacketFreeExtData(p);
     if (p->flags & PKT_ALLOC)
         PacketFree(p);
     else
index 531af50c33baa2f7b0695a50738ef2412b6eb810..ec4a4fe116539f093eaebb84e4ea2562871ce22f 100644 (file)
@@ -273,14 +273,6 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
         p->root = NULL;
     }
 
-    /* if p uses extended data, free them */
-    if (p->ext_pkt) {
-        if (!(p->flags & PKT_ZERO_COPY)) {
-            SCFree(p->ext_pkt);
-        }
-        p->ext_pkt = NULL;
-    }
-
     PACKET_PROFILING_END(p);
 
     p->ReleasePacket(p);