Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto3 with arena crashes with segfault in Clear() method in C++ #310

Closed
romange opened this issue Apr 28, 2015 · 3 comments
Closed

proto3 with arena crashes with segfault in Clear() method in C++ #310

romange opened this issue Apr 28, 2015 · 3 comments

Comments

@romange
Copy link

romange commented Apr 28, 2015

Sample code:

TEST_F(ProtoTest, Clear) {
  Arena arena;
  Person* person = Arena::CreateMessage<Person>(&arena);
  person->mutable_account()->set_bank_name("Foo");
  person->Clear();
}

The code below is generated with proto3 mode and it fails at the marked line because account_ was not allocated with new but with arena.

void Person::Clear() {
  name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),     GetArenaNoVirtual());
  id_ = GOOGLE_LONGLONG(0);
  email_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),     GetArenaNoVirtual());
  if (account_ != NULL) delete account_;            // ************
  account_ = NULL;
  phone_.Clear();
  phone2_.Clear();
  tag_.Clear();
}
@xfxyjwf
Copy link
Contributor

xfxyjwf commented Apr 28, 2015

@cfallin, could you take a look?

@cfallin
Copy link
Contributor

cfallin commented Apr 28, 2015

@romange, thanks for the report! I've reproduced the bug and it's an unfortunate interaction of the removal of field presence with arena support.

@xfxyjwf, I've sent you a change internally. @romange, it should appear in our GitHub repo once reviewed internally and on our next GitHub sync. Alternately, I can cherry-pick if critical.

@romange
Copy link
Author

romange commented Apr 29, 2015

Thanks, it's not urgent

@xfxyjwf xfxyjwf closed this as completed Jan 20, 2016
bithium pushed a commit to bithium/protobuf that referenced this issue Sep 4, 2023
Fast table-driven parsing for upb (2+GB/s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants