Skip to content

Commit 11ef0ff

Browse files
ckennellycopybara-github
authored andcommitted
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
1 parent b8eeefe commit 11ef0ff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/google/protobuf/arena.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
266266
ABSL_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
267267
<< "Requested size is too large to fit into size_t.";
268268
if (PROTOBUF_PREDICT_FALSE(arena == nullptr)) {
269-
return static_cast<T*>(::operator new[](num_elements * sizeof(T)));
269+
return new T[num_elements];
270270
} else {
271271
// We count on compiler to realize that if sizeof(T) is a multiple of
272272
// 8 AlignUpTo can be elided.

0 commit comments

Comments
 (0)