Skip to content

Commit

Permalink
Breaking Change: Ensure we allocate overaligned types with aligned op…
Browse files Browse the repository at this point in the history
…erator 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
  • Loading branch information
ckennelly authored and copybara-github committed Mar 29, 2024
1 parent b8eeefe commit 11ef0ff
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/google/protobuf/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 11ef0ff

Please sign in to comment.