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)
This commit is contained in:
Vadim Zeitlin 2023-10-23 01:48:09 +02:00
parent 0b0437af20
commit c816229fc3
2 changed files with 14 additions and 5 deletions

View File

@ -239,6 +239,10 @@ All (GUI):
- Fix refreshing multiple selection items in generic wxListCtrl. - Fix refreshing multiple selection items in generic wxListCtrl.
wxGTK:
- Fix losing clipboard contents due to a regression in 3.2.3.
wxMSW: wxMSW:
- Fix MSVS warning about redundant "const" in wx/itemid.h (#23590). - Fix MSVS warning about redundant "const" in wx/itemid.h (#23590).

View File

@ -594,11 +594,16 @@ void wxClipboard::Clear()
else else
{ {
// We need to free our data directly to avoid leaking memory. // We need to free our data directly to avoid leaking memory.
delete m_dataPrimary; if ( m_usePrimary )
m_dataPrimary = NULL; {
delete m_dataPrimary;
delete m_dataClipboard; m_dataPrimary = NULL;
m_dataClipboard = NULL; }
else
{
delete m_dataClipboard;
m_dataClipboard = NULL;
}
} }
m_targetRequested = 0; m_targetRequested = 0;