Skip to content

ACE_Thread_Manager leaks joinable terminated threads in wait_task() and wait_grp() #2502

@stranskypeter

Description

@stranskypeter

Version

ACE 8.0.2

Host machine and operating system

X86 Linux/Windows

Compiler name and version (including patch level)

msvc, gcc

Description

Threads leaving the ACE_Task::svc() method will terminate and are added to
ACE_Thread_Manager::terminated_thr_list_ for later cleanup. A call to wait_task()
and wait_grp() will call join for the threads from terminated_thr_list_ and free
system resources.

The list iterator to extract terminated threads from terminated_thr_list_ is
advanced in the for instruction and again inside the for loop. This
double advance causes a thread resource leakage. Likely 50% of the threads
are missed and will not get cleaned up before process exit.

ACE_Thread_Manager::wait_task()
...
for (...; titer.advance()) {
...
titer.advance_and_remove (false);
...
}

Sample fix/ workaround

Replace "for" by "while" loops
while(!titer.done ()) {
...
titer.advance...
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions