BIT-1885: fix input framework memory leak

For input threads that get joined during run-time instead of being
signalled to stop at termination-time as typical (e.g. an error occurs
or process exits w/ non-zero status) messages could remain in the
thread's queue and leak.

This patches threads to ensure they enter the proper "finished"
state so that the thread manager can attempt to fully process and
empty out their queues before joining them.
This commit is contained in:
Jon Siwek 2018-08-22 19:23:10 -05:00
parent f5848f0279
commit b847b3b4d9
3 changed files with 17 additions and 1 deletions

View file

@ -160,6 +160,7 @@ void Manager::Process()
for ( all_thread_list::iterator i = to_delete.begin(); i != to_delete.end(); i++ )
{
BasicThread* t = *i;
t->WaitForStop();
all_threads.remove(t);

View file

@ -21,6 +21,8 @@ public:
network_time(network_time) { }
virtual bool Process() {
if ( Object()->child_finished )
return true;
bool result = Object()->OnFinish(network_time);
Object()->Finished();
return result;
@ -90,7 +92,19 @@ public:
KillMeMessage(MsgThread* thread)
: OutputMessage<MsgThread>("ReporterMessage", thread) {}
virtual bool Process() { thread_mgr->KillThread(Object()); return true; }
virtual bool Process()
{
auto rval = true;
if ( ! Object()->child_finished )
{
rval = Object()->OnFinish(network_time);
Object()->Finished();
}
thread_mgr->KillThread(Object());
return rval;
}
};
#ifdef DEBUG

View file

@ -181,6 +181,7 @@ protected:
friend class HeartbeatMessage;
friend class FinishMessage;
friend class FinishedMessage;
friend class KillMeMessage;
/**
* Pops a message sent by the child from the child-to-main queue.