Vladislav Shpilevoy
authored
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 (cherry picked from commit 4ea29055)