QCoapMessagePrivate: make the d-tor virtual
To fix the AddressSanitizer error:
AddressSanitizer: new-delete-type-mismatch in thread T0:
object passed to delete has wrong type:
size of the allocated type: 104 bytes;
size of the deallocated type: 80 bytes.
QCoapMessage stores an instance of QCoapMessagePrivate in a
QSharedDataPointer. There is also a QCoapRequest class, which is
derived from QCoapMessage, and a QCoapRequestPrivate, which is derived
from QCoapMessagePrivate.
The QCoapRequest constructor creates an instance of QCoapRequestPrivate
and stores it in base class' d_ptr (which is
QSharedDataPointer<QCoapMessagePrivate>). This leads to an error shown
above.
Fix it by making QCoapMessagePrivate's d-tor virtual.
This revealed another issue - the non-const d_func() calls on
QCoapMessage were always calling QCoapMessagePrivate's copy c-tor,
which is incorrect if the d_ptr stores a QCoapRequestPrivate instance.
Fix it by introducing a virtual QCoapMessagePrivate::clone() function,
implementing it for both classes in the hierarchy, and providing a
specialization for QSharedDataPointer<QCoapMessagePrivate>, which uses
the clone() method.
This way we ensure that the detach goes via a virtual method, not via
a copy constructor.
Also make the copy constructors protected, to prevent future bugs.
Pick-to: 6.6 6.5 6.2
Change-Id: I865b8ce4733500120c12ac562a97e08b11c01c4c
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>