diff --git a/src/update-cb.cc b/src/update-cb.cc index ad8b2d63..1cd19e38 100644 --- a/src/update-cb.cc +++ b/src/update-cb.cc @@ -35,6 +35,11 @@ namespace conky { namespace priv { callback_base::~callback_base() + { + stop(); + } + + void callback_base::stop() { if(thread) { done = true; @@ -43,11 +48,16 @@ namespace conky { write(pipefd.second, "X", 1); thread->join(); delete thread; + thread = NULL; } - if(pipefd.first >= 0) + if(pipefd.first >= 0) { close(pipefd.first); - if(pipefd.second >= 0) + pipefd.first = -1; + } + if(pipefd.second >= 0) { close(pipefd.second); + pipefd.second = -1; + } } inline size_t callback_base::get_hash(const handle &h) diff --git a/src/update-cb.hh b/src/update-cb.hh index fb98634f..470d38c3 100644 --- a/src/update-cb.hh +++ b/src/update-cb.hh @@ -68,6 +68,13 @@ namespace conky { void run(); void start_routine(); + void stop(); + + static void deleter(callback_base *ptr) + { + ptr->stop(); + delete ptr; + } // a list of registered callbacks static Callbacks callbacks; @@ -118,7 +125,7 @@ namespace conky { typedef std::shared_ptr Base; callback_handle(Callback *ptr) - : Base(ptr) + : Base(ptr, &priv::callback_base::deleter) {} callback_handle(Base &&ptr)