Skip to content
Snippets Groups Projects
Commit 4ea29055 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

fiber: fix fibers with custom stack leak

Fibers with custom stack couldn't be reused via cord->dead list,
but neither were ever deleted via mempool_free(). They just leaked
until the cord was destroyed. Their custom stack also leaked.

It happened for all non-joinable custom-stack fibers. That was
because fiber_destroy() simply skipped the destruction if the
fiber is the current one.

It didn't affect joinable fibers because their fiber_destroy() is
done in another fiber. Their stack was deleted, but the fiber
itself still leaked.

The fix makes so fiber_destroy() is never called for the current
fiber. Instead, cord uses an approach like in pthread library -
the fiber who wants to be deleted is saved into cord->garbage
member. When some other fiber will want to be deleted in the
future, it will firstly cleanup the previous one and put self into
its place. And so on - fibers cleanup each other.

The process is optimized for the case when the fiber to delete is
not the current one - can delete it right away then.

NO_DOC=Bugfix
parent 6b913198
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment