Fix memory leak. Not all tasks are deleted in thread_d dtor

This commit is contained in:
Sandip Patel 2019-11-12 12:08:29 +05:30
parent 1f76279f63
commit d16ee316c9
2 changed files with 16 additions and 5 deletions

View file

@ -110,7 +110,7 @@ namespace fc {
thread::~thread() {
//wlog( "my ${n}", ("n",name()) );
if( my )
if( my && is_running() )
{
// wlog( "calling quit() on ${n}",("n",my->name) );
quit(); // deletes `my`
@ -333,6 +333,10 @@ namespace fc {
void thread::async_task( task_base* t, const priority& p, const time_point& tp ) {
assert(my);
if( !is_running() )
{
FC_THROW_EXCEPTION( canceled_exception, "Thread is not running.");
}
t->_when = tp;
// slog( "when %lld", t->_when.time_since_epoch().count() );
// slog( "delay %lld", (tp - fc::time_point::now()).count() );

View file

@ -42,7 +42,14 @@ namespace fc {
delete current;
fc::context* temp;
for (fc::context* ready_context : ready_heap)
{
if (ready_context->cur_task)
{
ready_context->cur_task->release();
ready_context->cur_task = nullptr;
}
delete ready_context;
}
ready_heap.clear();
while (blocked)
{
@ -509,10 +516,10 @@ namespace fc {
next->_set_active_context( current );
current->cur_task = next;
next->run();
fc::shared_ptr<task_base> next_ptr(next);
next_ptr->run();
current->cur_task = 0;
next->_set_active_context(0);
next->release();
next_ptr->_set_active_context(0);
current->reinitialize();
}