8725265
From b88646fc68cfc1c3840024fe3a59727c9eb9f95d Mon Sep 17 00:00:00 2001
8725265
From: Dennis Francis <dennisfrancis.in@gmail.com>
8725265
Date: Fri, 11 Dec 2015 09:19:22 +0530
8725265
Subject: [PATCH 2/3] Fix memleak of strings allocated in
8725265
 VclGtkClipboard::makeGtkTargetEntry
8725265
8725265
This leak is produced when copy and paste of text/numbers
8725265
is done in Calc/Writer.
8725265
8725265
Following is the trace produced by valgrind (trimmed)
8725265
8725265
  malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
8725265
  g_malloc (in /usr/lib64/libglib-2.0.so.0.4600.2)
8725265
  g_strdup (in /usr/lib64/libglib-2.0.so.0.4600.2)
8725265
  VclGtkClipboard::makeGtkTargetEntry(...) (gtk3gtkinst.cxx:467)
8725265
  VclGtkClipboard::setContents(...) (gtk3gtkinst.cxx:557)
8725265
  TransferableHelper::CopyToSelection(vcl::Window*) const (transfer.cxx:1019)
8725265
  ScTabView::CheckSelectionTransfer() (tabview3.cxx:319)
8725265
  ScTabView::UpdateAutoFillMark() (tabview3.cxx:144)
8725265
  ScTabView::SelectionChanged() (tabview3.cxx:365)
8725265
  ScViewFunc::PostPasteFromClip(ScRangeList const&, ScMarkData const&) (viewfun3.cxx:1753)
8725265
  ScViewFunc::PasteFromClip(...) (viewfun3.cxx:1415)
8725265
  ScClipUtil::PasteFromClipboard(ScViewData*, ScTabViewShell*, bool) (cliputil.cxx:69)
8725265
  ScCellShell::ExecuteEdit(SfxRequest&) (cellsh1.cxx:1285)
8725265
  SfxStubScCellShellExecuteEdit(SfxShell*, SfxRequest&) (scslots.hxx:7135)
8725265
  SfxShell::CallExec(void (*)(SfxShell*, SfxRequest&), SfxRequest&) (shell.hxx:206)
8725265
  SfxDispatcher::Call_Impl(SfxShell&, SfxSlot const&, SfxRequest&, bool) (dispatch.cxx:258)...
8725265
  ...
8725265
8725265
Change-Id: I12468e746f33a64e2b5f05e9ac1c6814c702ffd7
8725265
Reviewed-on: https://gerrit.libreoffice.org/20646
8725265
Reviewed-by: jan iversen <jani@documentfoundation.org>
8725265
Tested-by: jan iversen <jani@documentfoundation.org>
8725265
(cherry picked from commit 97df0e601a0d76664b4207d075fa6e2a5a51625c)
8725265
---
8725265
 vcl/unx/gtk3/gtk3gtkinst.cxx | 5 ++++-
8725265
 1 file changed, 4 insertions(+), 1 deletion(-)
8725265
8725265
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
8725265
index e9210d0..f1a9ddc 100644
8725265
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
8725265
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
8725265
@@ -456,7 +456,7 @@ void VclGtkClipboard::OwnerChanged(GtkClipboard* clipboard, GdkEvent* /*event*/)
8725265
 void VclGtkClipboard::ClipboardClear(GtkClipboard * /*clipboard*/)
8725265
 {
8725265
     for (auto &a : m_aGtkTargets)
8725265
-        free(a.target);
8725265
+        g_free(a.target);
8725265
     m_aGtkTargets.clear();
8725265
 }
8725265
 
8725265
@@ -518,6 +518,7 @@ VclGtkClipboard::~VclGtkClipboard()
8725265
     GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
8725265
     g_signal_handler_disconnect(clipboard, m_nOwnerChangedSignalId);
8725265
     g_object_unref(m_pOwner);
8725265
+    ClipboardClear(nullptr);
8725265
 }
8725265
 
8725265
 void VclGtkClipboard::setContents(
8725265
@@ -577,6 +578,8 @@ void VclGtkClipboard::setContents(
8725265
             //if there was a previous gtk_clipboard_set_with_data call then
8725265
             //ClipboardClearFunc will be called now
8725265
             GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
8725265
+            if(G_OBJECT(m_pOwner) == gtk_clipboard_get_owner(clipboard))
8725265
+                gtk_clipboard_clear(clipboard);
8725265
             //use with_owner with m_pOwner so we can distinguish in handle_owner_change
8725265
             //if we have gained or lost ownership of the clipboard
8725265
             gtk_clipboard_set_with_owner(clipboard, aGtkTargets.data(), aGtkTargets.size(),
8725265
-- 
8725265
2.5.0
8725265