From: Eric Leblond Date: Fri, 4 Mar 2016 18:22:46 +0000 (+0100) Subject: tm-threads: fix memleak X-Git-Tag: suricata-3.0.1RC1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41e540f2f19df61c480d8bd30e761a8cff2c242e;p=thirdparty%2Fsuricata.git tm-threads: fix memleak 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) --- diff --git a/src/tm-threads.c b/src/tm-threads.c index f0990f1343..d5326e9f23 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -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. *