1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 20:31:17 +00:00

Fix a crash on exit when using curl

The problem was that the callback thread is destroyed only in the destructor of the callback_base
class (which is called after the destructor of the derived classes). This means that the thread
is running even when it's object is partly destroyed, which can cause segfaults, race conditions
and other nasty problems.

I've fixed it so that the thread is destroyed before the underlying object's destructor is
called.
This commit is contained in:
Pavel Labath 2011-09-28 18:31:05 +02:00
parent 7c87003bde
commit b2331969d5
2 changed files with 20 additions and 3 deletions

View File

@ -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)

View File

@ -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<Callback> Base;
callback_handle(Callback *ptr)
: Base(ptr)
: Base(ptr, &priv::callback_base::deleter)
{}
callback_handle(Base &&ptr)