]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
nflog: fix memory leaks
authorGiuseppe Longo <giuseppelng@gmail.com>
Fri, 6 Jun 2014 09:48:15 +0000 (11:48 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 6 Jun 2014 09:57:45 +0000 (11:57 +0200)
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

src/source-nflog.c

index 1bda45b0e5b3adc7116a15a797018781a56c423d..dffa98d255da65555da81dfa6740b1d9d88581c7 100644 (file)
@@ -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;
     }