]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
tm-threads: fix memleak
authorEric Leblond <eric@regit.org>
Fri, 4 Mar 2016 18:22:46 +0000 (19:22 +0100)
committerEric Leblond <eric@regit.org>
Mon, 7 Mar 2016 22:29:58 +0000 (23:29 +0100)
Fix cleaning of threads where mutex and condition where not freed.

This fixes:

352 (192 direct, 160 indirect) bytes in 4 blocks are definitely lost in loss record 301 of 327
   at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x909404: TmThreadInitMC (tm-threads.c:1764)
   by 0x908DE7: TmThreadCreate (tm-threads.c:1120)
   by 0x90A326: TmThreadCreateMgmtThread (tm-threads.c:1183)
   by 0x4CA0AD: StatsSpawnThreads (counters.c:856)
   by 0x87F254: UnixSocketPcapFilesCheck (runmode-unix-socket.c:396)
   by 0x910330: UnixCommandBackgroundTasks (unix-manager.c:430)
   by 0x9140DD: UnixManager (unix-manager.c:980)
   by 0x9077F3: TmThreadsManagement (tm-threads.c:600)
   by 0x68DE283: start_thread (pthread_create.c:333)
   by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so)

src/tm-threads.c

index f0990f13432fda504b7393363ac7fffc1ffdf134..d5326e9f23857cc1b18e1b61605d1073f9736e84 100644 (file)
@@ -73,6 +73,8 @@ __thread uint64_t rwr_lock_cnt;
 /* prototypes */
 static int SetCPUAffinity(uint16_t cpu);
 
+static void TmThreadDeinitMC(ThreadVars *tv);
+
 /* root of the threadvars list */
 ThreadVars *tv_root[TVT_MAX] = { NULL };
 
@@ -1654,6 +1656,8 @@ void TmThreadFree(ThreadVars *tv)
 
     StatsThreadCleanup(tv);
 
+    TmThreadDeinitMC(tv);
+
     s = (TmSlot *)tv->tm_slots;
     while (s) {
         ps = s;
@@ -1780,6 +1784,19 @@ void TmThreadInitMC(ThreadVars *tv)
     return;
 }
 
+static void TmThreadDeinitMC(ThreadVars *tv)
+{
+    if (tv->ctrl_mutex) {
+        SCCtrlMutexDestroy(tv->ctrl_mutex);
+        SCFree(tv->ctrl_mutex);
+    }
+    if (tv->ctrl_cond) {
+        SCCtrlCondDestroy(tv->ctrl_cond);
+        SCFree(tv->ctrl_cond);
+    }
+    return;
+}
+
 /**
  * \brief Tests if the thread represented in the arg has been unpaused or not.
  *