Just figured out where exactly the problem is:
template
Q_OUTOFLINE_TEMPLATE void QSharedDataPointer
{
T *x = new T(*d);
x->ref.ref();
x = qAtomicSetPtr(&d, x);
if (!x->ref.deref())
delete x;
}
When the private data is detached a copy of it is created ( T *x = new T(*d);). The thing is that only the base class part is copied (Protocols::Generics::Packet::Data) instead of copying the derived class. The has no way to know what the correct type is of course.
The solution I can think of is to create our own PrivateData and PrivateDataPointer classes, actually modifying the ones from Qt, and adding a pure virtual copy ctor to the data class. The pointer class will call the virtual copy ctor to make sure a correct copy is created.
Any better ideas?
Regards,
Peter
Peter Dimov wrote:Hi all,
Attached is the log from valgrind after running the tester. Simply running the tester from the console results in segmentation fault. It’s strange this only happens when using PacketStub together with PacketDriver. From I can see from the log, when the shared data is copied, only the a partial copy is created - acutally only the part Generics::Packet::Data.
Also, it seems that not the right specialization of PacketDriver::readHeader() is called. The log says PacketDriver.h:201 but if must actually be PacketDriver.cpp:46.
I’ll look further into that but nevertheless any suggestions are welcome.
Regards,
Peter
