From c816229fc3635a040736ebe5274371c3a14ff4ee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Oct 2023 01:48:09 +0200 Subject: [PATCH] Fix losing the other selection contents in wxClipboard The memory leak fix in b52728a62a (Fix memory leak of wxClipboard data on exit, 2023-06-21) was too eager and destroyed not just the currently used selection (e.g. primary), but also the other one (secondary) when Clear() was called, which was wrong and resulted in the loss of clipboard contents when discarding the primary selection in wxSTC, for example. Fix this by only deleting the object corresponding to the selection which we're clearing. See #23661, #23988. (cherry picked from commit dc6a0c069bdde714f22cb0459efd9ad186ce7179) --- docs/changes.txt | 4 ++++ src/gtk/clipbrd.cpp | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 05ea6bfa61..7bebeda7fc 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -239,6 +239,10 @@ All (GUI): - Fix refreshing multiple selection items in generic wxListCtrl. +wxGTK: + +- Fix losing clipboard contents due to a regression in 3.2.3. + wxMSW: - Fix MSVS warning about redundant "const" in wx/itemid.h (#23590). diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 2773864030..d8f66ea732 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -594,11 +594,16 @@ void wxClipboard::Clear() else { // We need to free our data directly to avoid leaking memory. - delete m_dataPrimary; - m_dataPrimary = NULL; - - delete m_dataClipboard; - m_dataClipboard = NULL; + if ( m_usePrimary ) + { + delete m_dataPrimary; + m_dataPrimary = NULL; + } + else + { + delete m_dataClipboard; + m_dataClipboard = NULL; + } } m_targetRequested = 0;