From 39b6480e675051665157e61e12e9706f554e7d7c Mon Sep 17 00:00:00 2001 From: Ibraim Ganiev Date: Tue, 21 Oct 2025 20:55:28 +0300 Subject: [PATCH] Fix potential bug with incorrect freeing of block of memory across dll boundary --- taskflow/utility/object_pool.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/taskflow/utility/object_pool.hpp b/taskflow/utility/object_pool.hpp index d9f225494..94024c415 100644 --- a/taskflow/utility/object_pool.hpp +++ b/taskflow/utility/object_pool.hpp @@ -101,6 +101,7 @@ class ObjectPool { struct Block { std::atomic heap; + GlobalHeap* g_heap; Blocklist list_node; size_t i; size_t u; @@ -626,6 +627,7 @@ T* ObjectPool::animate(ArgsT&&... args) { s = new Block(); s->heap = &h; + s->g_heap = &_gheap; s->i = 0; s->u = 0; s->top = nullptr; @@ -695,7 +697,7 @@ void ObjectPool::recycle(T* mem) { // the block is in global heap if(h == nullptr) { - std::lock_guard glock(_gheap.mutex); + std::lock_guard glock(s->g_heap->mutex); if(s->heap == h) { sync = true; _deallocate(s, mem); @@ -729,8 +731,8 @@ void ObjectPool::recycle(T* mem) { h->u = h->u - x->u; h->a = h->a - M; x->heap = nullptr; - std::lock_guard glock(_gheap.mutex); - _blocklist_move_front(&x->list_node, &_gheap.list); + std::lock_guard glock(s->g_heap->mutex); + _blocklist_move_front(&x->list_node, &s->g_heap.list); break; } }