mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Fix two concurrency bugs found with ThreadSanitizer: 1. size() and byteSize() read _next_slot/_n_slots without the mutex, racing with store(). Add AtomicTransaction to both. 2. _grow() with concurrent writers causes buffer overflow: _n_slots is read outside the lock for malloc sizing but inside the lock for memcpy, so another thread's growth can make memcpy exceed the allocation. On POSIX, hold the lock throughout _grow() since malloc/free work fine under a mutex. Keep the CAS-based approach on NuttX where malloc can't be called with IRQs disabled. Add DynamicSparseLayerTest with concurrent stress tests that reproduce both issues. This issue was originally found while running the new SIH based CI tests.