Breaking Change: Ensure we allocate overaligned types with aligned operator new.

* The alignment may be incorrect.
* Using delete[] otherwise mismatches, since it was not allocated with
  overaligned operator new.

Additionally, we add a test to ensure we do not value initialize in this case.

PiperOrigin-RevId: 620241337
pull/16330/head
Chris Kennelly 12 months ago committed by Copybara-Service
parent b8eeefe663
commit 11ef0ffb87
  1. 2
      src/google/protobuf/arena.h

@ -266,7 +266,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
ABSL_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
<< "Requested size is too large to fit into size_t.";
if (PROTOBUF_PREDICT_FALSE(arena == nullptr)) {
return static_cast<T*>(::operator new[](num_elements * sizeof(T)));
return new T[num_elements];
} else {
// We count on compiler to realize that if sizeof(T) is a multiple of
// 8 AlignUpTo can be elided.

Loading…
Cancel
Save