From 11ef0ffb873ebd270ab0266270ea965a04c5f2e5 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Fri, 29 Mar 2024 07:41:41 -0700 Subject: [PATCH] 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 --- src/google/protobuf/arena.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index a13fccf93e37..c8ccfe24a14e 100644 --- a/src/google/protobuf/arena.h +++ b/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::max() / sizeof(T)) << "Requested size is too large to fit into size_t."; if (PROTOBUF_PREDICT_FALSE(arena == nullptr)) { - return static_cast(::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.