Browse Source

Increase the allocated_size_ should be after allocation. Otherwise there might have segmentation fault if allocation throws an exception.

jieluo@google.com 11 years ago
parent
commit
9eda53a6f1
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/google/protobuf/repeated_field.h

+ 1 - 1
src/google/protobuf/repeated_field.h

@@ -897,8 +897,8 @@ inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add() {
     return cast<TypeHandler>(elements_[current_size_++]);
   }
   if (allocated_size_ == total_size_) Reserve(total_size_ + 1);
-  ++allocated_size_;
   typename TypeHandler::Type* result = TypeHandler::New();
+  ++allocated_size_;
   elements_[current_size_++] = result;
   return result;
 }