Skip to content

Commit c816229

Browse files
committed
Fix losing the other selection contents in wxClipboard
The memory leak fix in b52728a (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 wxWidgets#23661, wxWidgets#23988. (cherry picked from commit dc6a0c0)
1 parent 0b0437a commit c816229

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

docs/changes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ All (GUI):
239239

240240
- Fix refreshing multiple selection items in generic wxListCtrl.
241241

242+
wxGTK:
243+
244+
- Fix losing clipboard contents due to a regression in 3.2.3.
245+
242246
wxMSW:
243247

244248
- Fix MSVS warning about redundant "const" in wx/itemid.h (#23590).

src/gtk/clipbrd.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,16 @@ void wxClipboard::Clear()
594594
else
595595
{
596596
// We need to free our data directly to avoid leaking memory.
597-
delete m_dataPrimary;
598-
m_dataPrimary = NULL;
599-
600-
delete m_dataClipboard;
601-
m_dataClipboard = NULL;
597+
if ( m_usePrimary )
598+
{
599+
delete m_dataPrimary;
600+
m_dataPrimary = NULL;
601+
}
602+
else
603+
{
604+
delete m_dataClipboard;
605+
m_dataClipboard = NULL;
606+
}
602607
}
603608

604609
m_targetRequested = 0;

0 commit comments

Comments
 (0)