tm-queue: unify queue name handling

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
pull/1910/head
Eric Leblond 10 years ago
parent f34fe85cfe
commit de6a37f17b

@ -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;
}

@ -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;
}

Loading…
Cancel
Save