From 83f01b36a11734fd91a4e7aad99c15463858fe4a Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 5 Nov 2023 18:56:43 +0000 Subject: When copying a message also copy the source string. --- include/clientprotocol.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/clientprotocol.h') diff --git a/include/clientprotocol.h b/include/clientprotocol.h index c606dd670..d686cd947 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -92,8 +92,10 @@ class CoreExport ClientProtocol::TagSelection class CoreExport ClientProtocol::MessageSource { + protected: User* sourceuser; const std::string* sourcestr; + bool sourceowned:1; public: /** Constructor, sets the source to be the full host of a user or sets it to be nothing. @@ -102,10 +104,17 @@ class CoreExport ClientProtocol::MessageSource * Optional, defaults to NULL. */ MessageSource(User* Sourceuser = NULL) + : sourceowned(false) { SetSourceUser(Sourceuser); } + ~MessageSource() + { + if (sourceowned && sourcestr) + delete sourcestr; + } + /** Constructor, sets the source to the supplied string and optionally sets the source user. * @param Sourcestr String to use as message source for serialization purposes. Must remain valid * as long as this object is alive. @@ -114,6 +123,7 @@ class CoreExport ClientProtocol::MessageSource * Useful when the source string is synthesized but it is still related to a User. */ MessageSource(const std::string& Sourcestr, User* Sourceuser = NULL) + : sourceowned(false) { SetSource(Sourcestr, Sourceuser); } @@ -451,6 +461,12 @@ class CoreExport ClientProtocol::Message : public ClientProtocol::MessageSource if (!curr.IsOwned()) ReplaceParam(j, curr); } + + if (GetSource()) + { + sourcestr = new std::string(*GetSource()); + sourceowned = true; + } } void SetSideEffect(bool Sideeffect) { sideeffect = Sideeffect; } -- cgit v1.3.1-10-gc9f91