From bf5b9df2904f75fe14d83720d93856c7ed0c1b57 Mon Sep 17 00:00:00 2001 From: ExMix Date: Fri, 1 Nov 2013 15:31:20 +0300 Subject: [PATCH] memory leak fix correct deletion ThreadPool::Impl after manual call stop --- base/thread_pool.cpp | 6 ++++++ base/thread_pool.hpp | 1 + 2 files changed, 7 insertions(+) diff --git a/base/thread_pool.cpp b/base/thread_pool.cpp index f13ef1ceab..ddb29d862c 100644 --- a/base/thread_pool.cpp +++ b/base/thread_pool.cpp @@ -89,6 +89,7 @@ namespace threads delete m_threads[i].first; } + m_threads.clear(); m_tasks.ProcessList(bind(&ThreadPool::Impl::FinishTasksOnStop, this, _1)); m_tasks.Clear(); } @@ -115,6 +116,11 @@ namespace threads ThreadPool::ThreadPool(size_t size, const finish_routine_fn & finishFn) : m_impl(new Impl(size, finishFn)) {} + ThreadPool::~ThreadPool() + { + delete m_impl; + } + void ThreadPool::AddTask(threads::IRoutine * routine) { m_impl->PushBack(routine); diff --git a/base/thread_pool.hpp b/base/thread_pool.hpp index 2bdf4a0706..f8188c1e85 100644 --- a/base/thread_pool.hpp +++ b/base/thread_pool.hpp @@ -12,6 +12,7 @@ namespace threads { public: ThreadPool(size_t size, const finish_routine_fn & finishFn); + ~ThreadPool(); // ThreadPool will not delete routine. You can delete it in finish_routine_fn if need void AddTask(threads::IRoutine * routine);