libfuse: thread_pool/objpool/fuse_loop - safer memory and iteration

- ThreadPool::destroy used to iterate _threads directly while another
  thread could be adjusting the same vector. Snapshot the vector
  under the mutex and iterate the local copy for pthread_cancel /
  pthread_join.

- ObjPool::construct now returns NULL when the pooled allocator
  returns NULL instead of invoking placement-new on a null
  pointer. In destroy, compute to_node(obj) before running the
  destructor - the destructor may scrub bytes the to_node helper
  reads.

- In the async/sync workers in fuse_loop, msgbuf_alloc can return
  NULL under memory pressure. Fail the worker cleanly with a
  diagnostic rather than dereferencing. Also introduce a small
  _nproc() helper that treats hardware_concurrency()==0 as 1, so
  the downstream min/max arithmetic doesn't produce a zero thread
  count.
This commit is contained in:
Antonio S. Musumeci 2026-04-18 01:00:32 -04:00
parent 23ec04cc5d
commit a5043d801a
3 changed files with 37 additions and 34 deletions

View file

@ -214,6 +214,9 @@ private:
static_cast<void*>(node) :
_allocator.allocate(size_, alignof(T)));
if(not mem)
return nullptr;
try
{
return new(mem) T(std::forward<Args>(args_)...);
@ -242,12 +245,13 @@ public:
if(not obj_)
return;
bool should_pool = _should_pool(obj_);
bool should_pool = _should_pool(obj_);
Node *node = to_node(obj_);
obj_->~T();
if(should_pool)
_push_node(to_node(obj_),size_);
_push_node(node,size_);
else
_allocator.deallocate(obj_,size_,alignof(T));
}