]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
tm-queue: unify queue name handling
authorEric Leblond <eric@regit.org>
Fri, 4 Mar 2016 18:13:43 +0000 (19:13 +0100)
committerEric Leblond <eric@regit.org>
Mon, 7 Mar 2016 22:28:47 +0000 (23:28 +0100)
Queue name was sometimes allocated and sometimes not. This
patch updates the behavior of creation function so it is
always allocated. This way we can free it at exit and fix
memory leak.

This fixes:

900 bytes in 110 blocks are definitely lost in loss record 322 of 329
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x803E0A9: strdup (in /lib/x86_64-linux-gnu/libc-2.21.so)
   by 0x90090E: StoreQueueId (tmqh-flow.c:112)
   by 0x8FFEA8: TmqhOutputFlowSetupCtx (tmqh-flow.c:180)
   by 0x908C7F: TmThreadCreate (tm-threads.c:1095)
   by 0x909982: TmThreadCreatePacketHandler (tm-threads.c:1154)
   by 0x87906F: RunModeFilePcapAutoFp (runmode-pcap-file.c:188)
   by 0x88376B: RunModeDispatch (runmodes.c:372)
   by 0x87F245: UnixSocketPcapFilesCheck (runmode-unix-socket.c:393)
   by 0x9102B0: UnixCommandBackgroundTasks (unix-manager.c:430)
   by 0x91405D: UnixManager (unix-manager.c:980)
   by 0x907773: TmThreadsManagement (tm-threads.c:600)

tm-queue: fix logic WIP

src/tm-queues.c
src/tmqh-flow.c

index e549a975c7b067615cdbd6faed8cc00b82b6f289..b956c714984c14072e7883ccbf99f5658d14f9b7 100644 (file)
@@ -52,7 +52,10 @@ Tmq* TmqCreateQueue(char *name)
         goto error;
 
     Tmq *q = &tmqs[tmq_id];
-    q->name = name;
+    q->name = SCStrdup(name);
+    if (q->name == NULL)
+        goto error;
+
     q->id = tmq_id++;
     /* for cuda purposes */
     q->q_type = 0;
@@ -90,6 +93,12 @@ void TmqDebugList(void)
 
 void TmqResetQueues(void)
 {
+    uint16_t i;
+    for (i = 0; i < TMQ_MAX_QUEUES; i++) {
+        if (tmqs[i].name) {
+            SCFree(tmqs[i].name);
+        }
+    }
     memset(&tmqs, 0x00, sizeof(tmqs));
     tmq_id = 0;
 }
index c0898ef0afcb6298b5c0bda5e494af8a2f55afbf..6ea8917bdba225b524ad1de805686d37d98a0721 100644 (file)
@@ -109,7 +109,7 @@ static int StoreQueueId(TmqhFlowCtx *ctx, char *name)
     void *ptmp;
     Tmq *tmq = TmqGetQueueByName(name);
     if (tmq == NULL) {
-        tmq = TmqCreateQueue(SCStrdup(name));
+        tmq = TmqCreateQueue(name);
         if (tmq == NULL)
             return -1;
     }