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
Showing
- changelogs/unreleased/fiber-custom-stack-leak.md 5 additions, 0 deletionschangelogs/unreleased/fiber-custom-stack-leak.md
- src/lib/core/fiber.c 52 additions, 17 deletionssrc/lib/core/fiber.c
- src/lib/core/fiber.h 21 additions, 0 deletionssrc/lib/core/fiber.h
- test/unit/fiber.cc 17 additions, 0 deletionstest/unit/fiber.cc
- test/unit/fiber_stack.c 21 additions, 1 deletiontest/unit/fiber_stack.c
- test/unit/fiber_stack.result 9 additions, 5 deletionstest/unit/fiber_stack.result
Loading