diff --git a/src/protocol/ProtocolMessage.h b/src/protocol/ProtocolMessage.h index 000f97bc0a..e34c8f6b40 100644 --- a/src/protocol/ProtocolMessage.h +++ b/src/protocol/ProtocolMessage.h @@ -106,7 +106,7 @@ class ProtocolMessage : public CommMessageOut, public CommMessageIn this->size_limit = message.size_limit; this->attachment = message.attachment; message.attachment = NULL; - this->wrapper = message.wrapper; + this->wrapper = NULL; } ProtocolMessage& operator = (ProtocolMessage&& message) @@ -117,7 +117,6 @@ class ProtocolMessage : public CommMessageOut, public CommMessageIn delete this->attachment; this->attachment = message.attachment; message.attachment = NULL; - this->wrapper = message.wrapper; } return *this; @@ -145,22 +144,28 @@ class ProtocolWrapper : public ProtocolMessage return this->message->inner(); } +protected: + void set_message(ProtocolMessage *message) + { + this->message = message; + if (message) + message->wrapper = this; + } + protected: ProtocolMessage *message; public: ProtocolWrapper(ProtocolMessage *message) { - message->wrapper = this; - this->message = message; + this->set_message(message); } public: ProtocolWrapper(ProtocolWrapper&& wrapper) : ProtocolMessage(std::move(wrapper)) { - wrapper.message->wrapper = this; - this->message = wrapper.message; + this->set_message(wrapper.message); wrapper.message = NULL; } @@ -169,8 +174,7 @@ class ProtocolWrapper : public ProtocolMessage if (&wrapper != this) { *(ProtocolMessage *)this = std::move(wrapper); - wrapper.message->wrapper = this; - this->message = wrapper.message; + this->set_message(wrapper.message); wrapper.message = NULL; }