Skip to content

HltEventLoopMgr: Fix memory leaks of EventContext, IOpaqueAddress and std::thread

Rafal Bielski requested to merge rbielski/athena:hlt-mem-leak into master

Fixing three memory leaks - trivial std::thread leak at end of run, and two non-trivial per-event leaks discovered while investigating a much bigger unrelated leak in ATR-20697 - one of EventContext and one of IOpaqueAddress.

The EventContext leak arised from !23528 (merged). There is some logic in the HLT loop manager to avoid using thread-local context in I/O services which relies on recording the EventContext in the event store. This means the event store owns the object and deletes it on store clearing. After !23528 (merged) it was not possible to pass the store-owned context to IEventProcessor::executeRun which uses move semantics, so Charles made a copy of the event context and that copy is passed to the Scheduler. I didn't realise back then that now the event store clearing doesn't take care of deleting that copy of the EventContext, so it has to be explicitly deleted in HltEventLoopMgr::drainScheduler. This also includes cases when event processing is interrupted and we exit from the function early via HLT_DRAINSCHED_CHECK.

I removed the need for one extra copy of the EventContext by creating the unique_ptr directly from createEventContext() return value, and also improved the syntax and comments in the place where we create the copy.

The IOpaqueAddress leak simply came from old interfaces with bare pointers (or pointer reference in this case) where it was not totally obvious that the ownership is passed and the object has to be deleted by the caller.

cc @bwynne, @fwinkl

Edited by Rafal Bielski

Merge request reports