summaryrefslogtreecommitdiff
path: root/vcl/jsdialog/jsdialogbuilder.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2023-04-03 14:04:44 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-04-05 17:02:46 +0200
commite57d5daaea734ade43e8251120afa031099a0840 (patch)
tree671870d9d8338791682dd489564e5d8802b2cfa2 /vcl/jsdialog/jsdialogbuilder.cxx
parente4042da6e63ed2ac6e1687f696580d9a502bad83 (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 'vcl/jsdialog/jsdialogbuilder.cxx')
-rw-r--r--vcl/jsdialog/jsdialogbuilder.cxx15
1 files changed, 7 insertions, 8 deletions
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 39da090326e9..a55242ffae58 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -71,7 +71,7 @@ void JSDialogNotifyIdle::send(tools::JsonWriter& aJsonWriter)
{
if (!m_aNotifierWindow)
{
- free(aJsonWriter.extractData());
+ aJsonWriter.finishAndGetAsOString();
return;
}
@@ -81,18 +81,17 @@ void JSDialogNotifyIdle::send(tools::JsonWriter& aJsonWriter)
if (m_bForce || !aJsonWriter.isDataEquals(m_LastNotificationMessage))
{
m_bForce = false;
- m_LastNotificationMessage = aJsonWriter.extractAsStdString();
- pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG,
- m_LastNotificationMessage.c_str());
+ m_LastNotificationMessage = aJsonWriter.finishAndGetAsOString();
+ pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, m_LastNotificationMessage);
}
else
{
- free(aJsonWriter.extractData());
+ aJsonWriter.finishAndGetAsOString();
}
}
else
{
- free(aJsonWriter.extractData());
+ aJsonWriter.finishAndGetAsOString();
}
}
@@ -1276,8 +1275,8 @@ JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent, VclMessageType eMe
xMessageDialog->DumpAsPropertyTree(aJsonWriter);
aJsonWriter.put("id", xMessageDialog->GetLOKWindowId());
aJsonWriter.put("jsontype", "dialog");
- std::unique_ptr<char[], o3tl::free_delete> message(aJsonWriter.extractData());
- pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.get());
+ OString message(aJsonWriter.finishAndGetAsOString());
+ pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message);
OUString sWindowId = OUString::number(xMessageDialog->GetLOKWindowId());
InsertWindowToMap(sWindowId);