@@ -168,9 +168,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
168168
169169 ~RepeatedPtrFieldBase() {
170170#ifndef NDEBUG
171- // Try to trigger segfault / asan failure in non-opt builds if arena_
172- // lifetime has ended before the destructor.
173- if (arena_) (void)arena_->SpaceAllocated();
171+ // Try to trigger segfault / asan failure in non-opt builds if the arena
172+ // lifetime has ended before the destructor. Note that `GetArena()` is
173+ // not free, but this is debug-only.
174+ const Arena* arena = GetArena();
175+ if (arena != nullptr) (void)arena->SpaceAllocated();
174176#endif
175177 }
176178
@@ -228,7 +230,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
228230
229231 // TODO: arena check is redundant once all `RepeatedPtrField`s
230232 // with non-null arena are owned by the arena.
231- if (ABSL_PREDICT_FALSE(arena_ != nullptr)) return;
233+ if (ABSL_PREDICT_FALSE(GetArena() != nullptr)) return;
232234
233235 using H = CommonHandler<TypeHandler>;
234236 int n = allocated_size();
@@ -481,7 +483,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
481483 // this case because otherwise a loop calling AddAllocated() followed by
482484 // Clear() would leak memory.
483485 using H = CommonHandler<TypeHandler>;
484- Delete<H>(element_at(current_size_), arena_ );
486+ Delete<H>(element_at(current_size_), GetArena() );
485487 } else if (current_size_ < allocated_size()) {
486488 // We have some cleared objects. We don't care about their order, so we
487489 // can just move the first one to the end to make space.
0 commit comments