From 754f75c1cdb2b681ac7c0f34c97e2ad8f3f89ece Mon Sep 17 00:00:00 2001 From: PB Date: Fri, 28 Jan 2022 21:35:06 +0100 Subject: [PATCH] Fix memory leaks in artprov sample The list control used in the Resources Browser dialog had dynamically allocated wxStrings assigned as item data that were never freed. Closes #22070. --- samples/artprov/artbrows.cpp | 8 ++++++++ samples/artprov/artbrows.h | 1 + 2 files changed, 9 insertions(+) diff --git a/samples/artprov/artbrows.cpp b/samples/artprov/artbrows.cpp index 2a7d3ba8da..882c0c1286 100644 --- a/samples/artprov/artbrows.cpp +++ b/samples/artprov/artbrows.cpp @@ -192,6 +192,14 @@ wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent) SetArtClient(wxART_MESSAGE_BOX); } +wxArtBrowserDialog::~wxArtBrowserDialog() +{ + const int itemCount = m_list->GetItemCount(); + + // item data are set by the ART_ICON macro + for ( int i = 0; i < itemCount; ++i ) + delete reinterpret_cast(m_list->GetItemData(i)); +} wxSize wxArtBrowserDialog::GetSelectedBitmapSize() const { diff --git a/samples/artprov/artbrows.h b/samples/artprov/artbrows.h index e1dbb093b5..3827762538 100644 --- a/samples/artprov/artbrows.h +++ b/samples/artprov/artbrows.h @@ -22,6 +22,7 @@ class wxArtBrowserDialog : public wxDialog { public: wxArtBrowserDialog(wxWindow *parent); + ~wxArtBrowserDialog(); void SetArtClient(const wxArtClient& client); void SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size = wxDefaultSize);