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