From 18c7eeefca86eaddfcdd8c19570582ac05c7fcbb Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Thu, 10 Apr 2014 13:11:34 +0200 Subject: [PATCH] packet handling: fix release function 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 | 14 ++++++++++++++ src/tmqh-packetpool.c | 8 -------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/decode.c b/src/decode.c index 1aa964c5f1..17ca90b3bc 100644 --- a/src/decode.c +++ b/src/decode.c @@ -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 diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 531af50c33..ec4a4fe116 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -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);