[libcxx-commits] [libcxx] [libc++] Use correct size for deallocation of arrays in shared_ptr (PR #68233)
Ilya Biryukov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 5 06:20:55 PDT 2023
================
@@ -1137,7 +1137,8 @@ struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count
__alloc_.~_Alloc();
size_t __size = __unbounded_array_control_block::__bytes_for(__count_);
_AlignedStorage* __storage = reinterpret_cast<_AlignedStorage*>(this);
- allocator_traits<_StorageAlloc>::deallocate(__tmp, _PointerTraits::pointer_to(*__storage), __size);
+ allocator_traits<_StorageAlloc>::deallocate(
+ __tmp, _PointerTraits::pointer_to(*__storage), __size / sizeof(_AlignedStorage));
----------------
ilya-biryukov wrote:
It actually seems to be more complicated.
The aligned storage has the size equal to the alignment of the control block (which is 8 bytes on my machine), so, e.g., we allocate and deallocate 5 elements of `AlignedStorage` for `int[]` when `__count_` is `0` (as the control block is 40 bytes on my machine).
In any case, I believe that reproducing exactly what gets passed to `allocate` is the right call here.
https://github.com/llvm/llvm-project/pull/68233
More information about the libcxx-commits
mailing list