diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2023-04-03 14:04:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-04-05 17:02:46 +0200 |
commit | e57d5daaea734ade43e8251120afa031099a0840 (patch) | |
tree | 671870d9d8338791682dd489564e5d8802b2cfa2 /desktop/inc | |
parent | e4042da6e63ed2ac6e1687f696580d9a502bad83 (diff) |
fix leaks when using tools::JsonWriter
Specifically in sd/source/core/annotations/Annotation.cxx
We seem to end up fixing leaks here often.
The current tools::JsonWriter API is just very hard to use correctly.
So rather return an OString, which is cheap to copy,
and push that down into the LOK code.
AFAIK that seems to end up requiring less code and less adhoc copying
of data (specifically the queueing code in init.cxx was creating
copies when converting to std::string).
Ideally, we could have some special API to avoid the new strdup()
calls in init.cxx, but not sure how to prevent other people
from accidentally using that.
Change-Id: Ia33437c1bfd9cc2d54dfb99914d1b72db20335f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149963
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'desktop/inc')
-rw-r--r-- | desktop/inc/lib/init.hxx | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx index cd6636ac2242..edc1b12a0c71 100644 --- a/desktop/inc/lib/init.hxx +++ b/desktop/inc/lib/init.hxx @@ -86,7 +86,7 @@ namespace desktop { return m_aRectangle.IsEmpty(); } - static RectangleAndPart Create(const std::string& rPayload); + static RectangleAndPart Create(const OString& rPayload); /// Makes sure a rectangle is valid (apparently some code does not like negative coordinates for example). static tools::Rectangle SanitizedRectangle(tools::Long nLeft, tools::Long nTop, tools::Long nWidth, tools::Long nHeight); static tools::Rectangle SanitizedRectangle(const tools::Rectangle& rect); @@ -100,7 +100,7 @@ namespace desktop { virtual ~CallbackFlushHandler() override; virtual void Invoke() override; // TODO This should be dropped and the binary libreOfficeKitViewCallback() variants should be called? - void queue(const int type, const char* data); + void queue(const int type, const OString& data); /// Disables callbacks on this handler. Must match with identical count /// of enableCallbacks. Used during painting and changing views. @@ -117,8 +117,8 @@ namespace desktop { void setViewId( int viewId ) { m_viewId = viewId; } // SfxLockCallbackInterface - virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override; - virtual void libreOfficeKitViewCallbackWithViewId(int nType, const char* pPayload, int nViewId) override; + virtual void libreOfficeKitViewCallback(int nType, const OString& pPayload) override; + virtual void libreOfficeKitViewCallbackWithViewId(int nType, const OString& pPayload, int nViewId) override; virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart, int nMode) override; virtual void libreOfficeKitViewUpdatedCallback(int nType) override; virtual void libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId, int nSourceViewId) override; @@ -128,13 +128,13 @@ namespace desktop { private: struct CallbackData { - CallbackData(const char* payload) - : PayloadString(payload ? payload : "(nil)") + CallbackData(OString payload) + : PayloadString(payload) { } - CallbackData(const char* payload, int viewId) - : PayloadString(payload ? payload : "(nil)") + CallbackData(OString payload, int viewId) + : PayloadString(payload) , PayloadObject(viewId) { } @@ -149,7 +149,7 @@ namespace desktop { { // PayloadString will be done on demand } - const std::string& getPayload() const; + const OString& getPayload() const; /// Update a RectangleAndPart object and update PayloadString if necessary. void updateRectangleAndPart(const RectangleAndPart& rRectAndPart); /// Return the parsed RectangleAndPart instance. @@ -165,7 +165,7 @@ namespace desktop { bool isEmpty() const { - return PayloadString.empty() && PayloadObject.which() == 0; + return PayloadString.isEmpty() && PayloadObject.which() == 0; } void clear() { @@ -180,7 +180,7 @@ namespace desktop { bool isCached() const { return PayloadObject.which() != 0; } private: - mutable std::string PayloadString; + mutable OString PayloadString; /// The parsed payload cache. Update validate() when changing this. mutable boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree, int> PayloadObject; @@ -204,9 +204,9 @@ namespace desktop { so we split the queue in 2 to make the scanning cache friendly. */ queue_type1 m_queue1; queue_type2 m_queue2; - std::map<int, std::string> m_states; - std::unordered_map<std::string, std::string> m_lastStateChange; - std::unordered_map<int, std::unordered_map<int, std::string>> m_viewStates; + std::map<int, OString> m_states; + std::unordered_map<OString, OString> m_lastStateChange; + std::unordered_map<int, std::unordered_map<int, OString>> m_viewStates; // For some types only the last message matters (see isUpdatedType()) or only the last message // per each viewId value matters (see isUpdatedTypePerViewId()), so instead of using push model |