From: Giuseppe Longo Date: Fri, 6 Jun 2014 09:48:15 +0000 (+0200) Subject: nflog: fix memory leaks X-Git-Tag: suricata-2.0.2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8db3f214f093f81e75402fdf0cd8d2e05a7cdc3a;p=thirdparty%2Fsuricata.git nflog: fix memory leaks This fixes the following memory leaks: [src/source-nflog.c:222]: (error) Memory leak: ntv [src/source-nflog.c:236]: (error) Memory leak: ntv [src/source-nflog.c:253]: (error) Memory leak: ntv [src/source-nflog.c:258]: (error) Memory leak: ntv --- diff --git a/src/source-nflog.c b/src/source-nflog.c index 1bda45b0e5..dffa98d255 100644 --- a/src/source-nflog.c +++ b/src/source-nflog.c @@ -209,18 +209,18 @@ static int NFLOGCallback(struct nflog_g_handle *gh, struct nfgenmsg *msg, TmEcode ReceiveNFLOGThreadInit(ThreadVars *tv, void *initdata, void **data) { NflogGroupConfig *nflconfig = initdata; - NFLOGThreadVars *ntv = SCMalloc(sizeof(NFLOGThreadVars)); - if (unlikely(ntv == NULL)) { - nflconfig->DerefFunc(nflconfig); + if (initdata == NULL) { + SCLogError(SC_ERR_INVALID_ARGUMENT, "initdata == NULL"); SCReturnInt(TM_ECODE_FAILED); } - memset(ntv, 0, sizeof(NFLOGThreadVars)); - if (initdata == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, "initdata == NULL"); + NFLOGThreadVars *ntv = SCMalloc(sizeof(NFLOGThreadVars)); + if (unlikely(ntv == NULL)) { + nflconfig->DerefFunc(nflconfig); SCReturnInt(TM_ECODE_FAILED); } + memset(ntv, 0, sizeof(NFLOGThreadVars)); ntv->tv = tv; ntv->group = nflconfig->group; @@ -233,6 +233,7 @@ TmEcode ReceiveNFLOGThreadInit(ThreadVars *tv, void *initdata, void **data) ntv->h = nflog_open(); if (ntv->h == NULL) { SCLogError(SC_ERR_NFLOG_OPEN, "nflog_open() failed"); + SCFree(ntv); return TM_ECODE_FAILED; } @@ -250,11 +251,13 @@ TmEcode ReceiveNFLOGThreadInit(ThreadVars *tv, void *initdata, void **data) ntv->gh = nflog_bind_group(ntv->h, ntv->group); if (!ntv->gh) { SCLogError(SC_ERR_NFLOG_OPEN, "nflog_bind_group() failed"); + SCFree(ntv); return TM_ECODE_FAILED; } if (nflog_set_mode(ntv->gh, NFULNL_COPY_PACKET, 0xFFFF) < 0) { SCLogError(SC_ERR_NFLOG_SET_MODE, "can't set packet_copy mode"); + SCFree(ntv); return TM_ECODE_FAILED; }