From e57d5daaea734ade43e8251120afa031099a0840 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 3 Apr 2023 14:04:44 +0200 Subject: 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 --- vcl/jsdialog/jsdialogbuilder.cxx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'vcl/jsdialog/jsdialogbuilder.cxx') 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 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); -- cgit