From: Victor Julien Date: Tue, 25 Apr 2023 05:22:15 +0000 (+0200) Subject: af/xdp: fix memory leaks on thread init failure X-Git-Tag: suricata-7.0.0-rc2~340 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc000a6d8118965ac372eed8eface9cbc721335a;p=thirdparty%2Fsuricata.git af/xdp: fix memory leaks on thread init failure source-af-xdp.c:675:21: warning: Potential leak of memory pointed to by 'ptv' [unix.Malloc] SCReturnInt(TM_ECODE_FAILED); ^~~~~~~~~~~~~~~ ./util-debug.h:275:48: note: expanded from macro 'SCReturnInt' #define SCReturnInt(x) return x ^ 1 warning generated. --- diff --git a/src/source-af-xdp.c b/src/source-af-xdp.c index 4036e05076..6f8f8815e0 100644 --- a/src/source-af-xdp.c +++ b/src/source-af-xdp.c @@ -628,6 +628,7 @@ static TmEcode ReceiveAFXDPThreadInit(ThreadVars *tv, const void *initdata, void if (SetIfaceFlags(ptv->iface, IFF_PROMISC | IFF_UP) != 0) { SCLogError("Failed to switch interface (%s) to promiscuous, error %s", ptv->iface, strerror(errno)); + SCFree(ptv); SCReturnInt(TM_ECODE_FAILED); } } @@ -672,10 +673,12 @@ static TmEcode ReceiveAFXDPThreadInit(ThreadVars *tv, const void *initdata, void /* Reserve memory for umem */ if (AcquireBuffer(ptv) != TM_ECODE_OK) { + SCFree(ptv); SCReturnInt(TM_ECODE_FAILED); } if (AFXDPSocketCreation(ptv) != TM_ECODE_OK) { + ReceiveAFXDPThreadDeinit(tv, ptv); SCReturnInt(TM_ECODE_FAILED); }