[libcxx-commits] [libcxx] [libc++] Use correct size for deallocation of arrays in shared_ptr (PR #68233)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 5 09:05:15 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));
----------------
sxeraverx wrote:

If `alignof(size_t) < sizeof(size_t)`, it will not be `__count_ + 1`.

https://github.com/llvm/llvm-project/pull/68233


More information about the libcxx-commits mailing list