I've been using C++ GPBs in a real-time robotics system and have been 
getting (VERY rarely) a segfault when I use a protobuf copy constructor. 
When I say very rarely, I mean once in hundreds of thousands of method 
calls. I've followed the gdb backtrace multiple times, and it's always THIS:

#0  0xad252ac5 in construct (this=0x8a00b20, __position=..., __x=...) at 
/usr/include/c++/4.6/ext/new_allocator.h:108
#1  std::vector<google::protobuf::UnknownField, 
std::allocator<google::protobuf::UnknownField> >::_M_insert_aux (
    this=0x8a00b20, __position=..., __x=...) at 
/usr/include/c++/4.6/bits/vector.tcc:335
#2  0xad25233c in push_back (this=0x8a07608, field=...) at 
/usr/include/c++/4.6/bits/stl_vector.h:834
#3  push_back (this=0x8a07608, field=...)
    at 
/path/to/protobuf/protobufsrc/src/google/protobuf/unknown_field_set.cc:140
#4  google::protobuf::UnknownFieldSet::AddField (this=0x8a07608, field=...)
    at 
/path/to/protobuf/protobufsrc/src/google/protobuf/unknown_field_set.cc:142
#5  0xad2523ac in google::protobuf::UnknownFieldSet::MergeFrom 
(this=0x8a07608, other=...)
    at 
/path/to/protobuf/protobufsrc/src/google/protobuf/unknown_field_set.cc:64
#6  0xad0eaacc in messages::MyProtobuf::MergeFrom(messages::MyProtobuf 
const&) ()
   from /path/to/our/library
#7  0xad0eb180 in messages::MyProtobuf::MyProtobuf(messages::MyProtobuf 
const&) ()
   from /path/to/our/library

The code it traces back to is:
        std::map<float, ClassWithGPBMember> cdf;

        float prev = 0.0f;
        for(iter = particles.begin(); iter != particles.end(); ++iter)
        {
            ClassWithGPBMember c = (*iter);

            // For loop continues
        }
Where ClassWithGPBMember has a member of type MyProtobuf (not a pointer). 
The copy in #7 above must come from the assignment in the first line of the 
for loop.

I have looked at UnknownFieldSet, and if I understand correctly, it holds 
unrecognized fields from when a message is parsed. My messages (at least at 
this stage of the code) have not been serialized or parsed; we create them 
and set the fields. There is no way for us to have added an unknown one. So 
my question is, how could I have interfered with the UnknownFieldSet 
without having done any parsing? Also, any ideas on why is would occur so 
rarely? I would typically guess a timing bug, but all processing of this 
message is within one thread.

Anybody seen this before or know what could cause this? It's a bit beyond 
my understanding of GPBs.

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to