Fix memory leak. Not all tasks are deleted in thread_d dtor #8
2 changed files with 16 additions and 5 deletions
|
|
@ -110,7 +110,7 @@ namespace fc {
|
||||||
|
|
||||||
thread::~thread() {
|
thread::~thread() {
|
||||||
//wlog( "my ${n}", ("n",name()) );
|
//wlog( "my ${n}", ("n",name()) );
|
||||||
if( my )
|
if( my && is_running() )
|
||||||
{
|
{
|
||||||
// wlog( "calling quit() on ${n}",("n",my->name) );
|
// wlog( "calling quit() on ${n}",("n",my->name) );
|
||||||
quit(); // deletes `my`
|
quit(); // deletes `my`
|
||||||
|
|
@ -333,6 +333,10 @@ namespace fc {
|
||||||
|
|
||||||
void thread::async_task( task_base* t, const priority& p, const time_point& tp ) {
|
void thread::async_task( task_base* t, const priority& p, const time_point& tp ) {
|
||||||
assert(my);
|
assert(my);
|
||||||
|
if( !is_running() )
|
||||||
|
{
|
||||||
|
FC_THROW_EXCEPTION( canceled_exception, "Thread is not running.");
|
||||||
|
}
|
||||||
t->_when = tp;
|
t->_when = tp;
|
||||||
// slog( "when %lld", t->_when.time_since_epoch().count() );
|
// slog( "when %lld", t->_when.time_since_epoch().count() );
|
||||||
// slog( "delay %lld", (tp - fc::time_point::now()).count() );
|
// slog( "delay %lld", (tp - fc::time_point::now()).count() );
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,14 @@ namespace fc {
|
||||||
delete current;
|
delete current;
|
||||||
fc::context* temp;
|
fc::context* temp;
|
||||||
for (fc::context* ready_context : ready_heap)
|
for (fc::context* ready_context : ready_heap)
|
||||||
delete ready_context;
|
{
|
||||||
|
if (ready_context->cur_task)
|
||||||
|
{
|
||||||
|
ready_context->cur_task->release();
|
||||||
|
ready_context->cur_task = nullptr;
|
||||||
|
}
|
||||||
|
delete ready_context;
|
||||||
|
}
|
||||||
ready_heap.clear();
|
ready_heap.clear();
|
||||||
while (blocked)
|
while (blocked)
|
||||||
{
|
{
|
||||||
|
|
@ -509,10 +516,10 @@ namespace fc {
|
||||||
|
|
||||||
next->_set_active_context( current );
|
next->_set_active_context( current );
|
||||||
current->cur_task = next;
|
current->cur_task = next;
|
||||||
next->run();
|
fc::shared_ptr<task_base> next_ptr(next);
|
||||||
|
next_ptr->run();
|
||||||
current->cur_task = 0;
|
current->cur_task = 0;
|
||||||
next->_set_active_context(0);
|
next_ptr->_set_active_context(0);
|
||||||
next->release();
|
|
||||||
current->reinitialize();
|
current->reinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue