mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-14 11:33:14 +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:
parent
7c87003bde
commit
b2331969d5
@ -35,6 +35,11 @@ namespace conky {
|
|||||||
|
|
||||||
namespace priv {
|
namespace priv {
|
||||||
callback_base::~callback_base()
|
callback_base::~callback_base()
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void callback_base::stop()
|
||||||
{
|
{
|
||||||
if(thread) {
|
if(thread) {
|
||||||
done = true;
|
done = true;
|
||||||
@ -43,11 +48,16 @@ namespace conky {
|
|||||||
write(pipefd.second, "X", 1);
|
write(pipefd.second, "X", 1);
|
||||||
thread->join();
|
thread->join();
|
||||||
delete thread;
|
delete thread;
|
||||||
|
thread = NULL;
|
||||||
}
|
}
|
||||||
if(pipefd.first >= 0)
|
if(pipefd.first >= 0) {
|
||||||
close(pipefd.first);
|
close(pipefd.first);
|
||||||
if(pipefd.second >= 0)
|
pipefd.first = -1;
|
||||||
|
}
|
||||||
|
if(pipefd.second >= 0) {
|
||||||
close(pipefd.second);
|
close(pipefd.second);
|
||||||
|
pipefd.second = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t callback_base::get_hash(const handle &h)
|
inline size_t callback_base::get_hash(const handle &h)
|
||||||
|
@ -68,6 +68,13 @@ namespace conky {
|
|||||||
|
|
||||||
void run();
|
void run();
|
||||||
void start_routine();
|
void start_routine();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
static void deleter(callback_base *ptr)
|
||||||
|
{
|
||||||
|
ptr->stop();
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
|
||||||
// a list of registered callbacks
|
// a list of registered callbacks
|
||||||
static Callbacks callbacks;
|
static Callbacks callbacks;
|
||||||
@ -118,7 +125,7 @@ namespace conky {
|
|||||||
typedef std::shared_ptr<Callback> Base;
|
typedef std::shared_ptr<Callback> Base;
|
||||||
|
|
||||||
callback_handle(Callback *ptr)
|
callback_handle(Callback *ptr)
|
||||||
: Base(ptr)
|
: Base(ptr, &priv::callback_base::deleter)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
callback_handle(Base &&ptr)
|
callback_handle(Base &&ptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user