diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index e0bae7f6e..2f7cb3246 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -2740,7 +2740,8 @@ void LabelTrack::CreateCustomGlyphs() // Create the icon from the tweaked spec. mBoundaryGlyphs[index] = wxBitmap(XmpBmp); // Create the mask - mBoundaryGlyphs[index].SetMask(new wxMask(mBoundaryGlyphs[index], wxColour(192, 192, 192))); + // SetMask takes ownership + mBoundaryGlyphs[index].SetMask(safenew wxMask(mBoundaryGlyphs[index], wxColour(192, 192, 192))); } } diff --git a/src/Menus.cpp b/src/Menus.cpp index cb548d5e1..8b87732e0 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -5370,7 +5370,7 @@ void AudacityProject::OnShowClipping() void AudacityProject::OnHistory() { if (!mHistoryWindow) - mHistoryWindow = new HistoryWindow(this, GetUndoManager()); + mHistoryWindow = safenew HistoryWindow(this, GetUndoManager()); mHistoryWindow->Show(); mHistoryWindow->Raise(); mHistoryWindow->UpdateDisplay(); @@ -5405,7 +5405,7 @@ void AudacityProject::OnPlotSpectrum() where.x = 150; where.y = 150; - mFreqWindow = new FreqWindow(this, -1, _("Frequency Analysis"), where); + mFreqWindow = safenew FreqWindow(this, -1, _("Frequency Analysis"), where); } mFreqWindow->Show(true); @@ -5422,7 +5422,7 @@ void AudacityProject::OnContrast() where.x = 150; where.y = 150; - mContrastDialog = new ContrastDialog(this, -1, _("Contrast Analysis (WCAG 2 compliance)"), where); + mContrastDialog = safenew ContrastDialog(this, -1, _("Contrast Analysis (WCAG 2 compliance)"), where); } mContrastDialog->CentreOnParent(); diff --git a/src/Project.cpp b/src/Project.cpp index 793e0d8c8..3545207f9 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -2033,8 +2033,8 @@ void AudacityProject::OnShow(wxShowEvent & event) // this is a pure wxWidgets event (no GDK event behind it) and that it // therefore isn't processed within the YieldFor(..) of the clipboard // operations (workaround for Debian bug #765341). - wxSizeEvent *sizeEvent = new wxSizeEvent(GetSize()); - GetEventHandler()->QueueEvent(sizeEvent); + // QueueEvent() will take ownership of the event + GetEventHandler()->QueueEvent(safenew wxSizeEvent(GetSize())); // Further processing by default handlers event.Skip(); diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index 0103d2e2b..9b149d7dd 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -2052,7 +2052,7 @@ GuiWaveTrack * ShuttleGui::AddGuiWaveTrack( const wxString & WXUNUSED(Name)) // return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), GuiWaveTrack); GuiWaveTrack * pGuiWaveTrack; miProp=1; - mpWind = pGuiWaveTrack = new GuiWaveTrack(mpParent, miId, Name); + mpWind = pGuiWaveTrack = safenew GuiWaveTrack(mpParent, miId, Name); mpWind->SetMinSize(wxSize(100,50)); UpdateSizers(); return pGuiWaveTrack; @@ -2096,7 +2096,7 @@ AttachableScrollBar * ShuttleGui::AddAttachableScrollBar( long style ) // return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), AttachableScrollBar); AttachableScrollBar * pAttachableScrollBar; miProp=0; - mpWind = pAttachableScrollBar = new AttachableScrollBar( + mpWind = pAttachableScrollBar = safenew AttachableScrollBar( mpParent, miId, wxDefaultPosition, diff --git a/src/TimerRecordDialog.cpp b/src/TimerRecordDialog.cpp index ff0579959..ceac1476c 100644 --- a/src/TimerRecordDialog.cpp +++ b/src/TimerRecordDialog.cpp @@ -804,7 +804,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S) S.StartStatic(_("Start Date and Time"), true); { m_pDatePickerCtrl_Start = - new wxDatePickerCtrl(this, // wxWindow *parent, + safenew wxDatePickerCtrl(this, // wxWindow *parent, ID_DATEPICKER_START, // wxWindowID id, m_DateTime_Start); // const wxDateTime& dt = wxDefaultDateTime, // const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDP_DEFAULT | wxDP_SHOWCENTURY, const wxValidator& validator = wxDefaultValidator, const wxString& name = "datectrl") @@ -815,7 +815,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S) #endif S.AddWindow(m_pDatePickerCtrl_Start); - m_pTimeTextCtrl_Start = new NumericTextCtrl( + m_pTimeTextCtrl_Start = safenew NumericTextCtrl( NumericConverter::TIME, this, ID_TIMETEXT_START); m_pTimeTextCtrl_Start->SetName(_("Start Time")); m_pTimeTextCtrl_Start->SetFormatString(strFormat); @@ -829,7 +829,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S) S.StartStatic(_("End Date and Time"), true); { m_pDatePickerCtrl_End = - new wxDatePickerCtrl(this, // wxWindow *parent, + safenew wxDatePickerCtrl(this, // wxWindow *parent, ID_DATEPICKER_END, // wxWindowID id, m_DateTime_End); // const wxDateTime& dt = wxDefaultDateTime, // const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDP_DEFAULT | wxDP_SHOWCENTURY, const wxValidator& validator = wxDefaultValidator, const wxString& name = "datectrl") @@ -840,7 +840,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S) #endif S.AddWindow(m_pDatePickerCtrl_End); - m_pTimeTextCtrl_End = new NumericTextCtrl( + m_pTimeTextCtrl_End = safenew NumericTextCtrl( NumericConverter::TIME, this, ID_TIMETEXT_END); m_pTimeTextCtrl_End->SetName(_("End Time")); m_pTimeTextCtrl_End->SetFormatString(strFormat); @@ -861,7 +861,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S) * seconds. */ wxString strFormat1 = _("099 days 024 h 060 m 060 s"); - m_pTimeTextCtrl_Duration = new NumericTextCtrl(NumericConverter::TIME, this, ID_TIMETEXT_DURATION); + m_pTimeTextCtrl_Duration = safenew NumericTextCtrl(NumericConverter::TIME, this, ID_TIMETEXT_DURATION); m_pTimeTextCtrl_Duration->SetName(_("Duration")); m_pTimeTextCtrl_Duration->SetFormatString(strFormat1); m_pTimeTextCtrl_Duration->SetValue(m_TimeSpan_Duration.GetSeconds().ToDouble()); diff --git a/src/TrackPanel.h b/src/TrackPanel.h index bee35c3ac..2bef7e17d 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -556,8 +556,8 @@ protected: // (no GDK event behind it) and that it therefore isn't processed // within the YieldFor(..) of the clipboard operations (workaround // for Debian bug #765341). - wxTimerEvent *event = new wxTimerEvent(*this); - parent->GetEventHandler()->QueueEvent(event); + // QueueEvent() will take ownership of the event + parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this)); } TrackPanel *parent; } mTimer; diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp index 32940cf26..63615c9a6 100644 --- a/src/toolbars/ToolBar.cpp +++ b/src/toolbars/ToolBar.cpp @@ -758,7 +758,7 @@ AButton * ToolBar::MakeButton(wxWindow *parent, wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff)); AButton * button = - new AButton(parent, id, placement, size, *up2, *hilite2, *down2, + safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2, *disable2, processdownevents); return button; diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp index 2a7986a7f..d7bc77099 100644 --- a/src/toolbars/ToolManager.cpp +++ b/src/toolbars/ToolManager.cpp @@ -1085,6 +1085,7 @@ void ToolManager::OnMouse( wxMouseEvent & event ) // Done with the floater mDragWindow->Destroy(); + mDragWindow = nullptr; mDragBar->Refresh(false); } else @@ -1335,7 +1336,7 @@ void ToolManager::OnGrabber( GrabberEvent & event ) mDragBar->SetPositioned(); // Construct a NEW floater - mDragWindow = new ToolFrame( mParent, this, mDragBar, mp ); + mDragWindow = safenew ToolFrame( mParent, this, mDragBar, mp ); // Make sure the ferry is visible mDragWindow->Show(); @@ -1377,6 +1378,7 @@ void ToolManager::HandleEscapeKey() // Done with the floater mDragWindow->ClearBar(); mDragWindow->Destroy(); + mDragWindow = nullptr; mDragBar->Refresh(false); } else { diff --git a/src/widgets/ASlider.cpp b/src/widgets/ASlider.cpp index 348fbf77d..beaaaebc9 100644 --- a/src/widgets/ASlider.cpp +++ b/src/widgets/ASlider.cpp @@ -705,7 +705,8 @@ void LWSlider::Draw(wxDC & paintDC) #if !defined(__WXMAC__) // Now create and set the mask - mThumbBitmap->SetMask(new wxMask(*mThumbBitmap, transparentColour)); + // SetMask takes ownership + mThumbBitmap->SetMask(safenew wxMask(*mThumbBitmap, transparentColour)); #endif // @@ -884,7 +885,8 @@ void LWSlider::Draw(wxDC & paintDC) dc.SelectObject(wxNullBitmap); #if !defined(__WXMAC__) - mBitmap->SetMask(new wxMask(*mBitmap, transparentColour)); + // SetMask takes ownership + mBitmap->SetMask(safenew wxMask(*mBitmap, transparentColour)); #endif } diff --git a/src/widgets/ErrorDialog.cpp b/src/widgets/ErrorDialog.cpp index 34a9cb628..0cb633142 100644 --- a/src/widgets/ErrorDialog.cpp +++ b/src/widgets/ErrorDialog.cpp @@ -184,11 +184,13 @@ void ShowModelessErrorDialog(wxWindow *parent, const wxString &helpURL, const bool Close) { - ErrorDialog *dlog = new ErrorDialog(parent, dlogTitle, message, helpURL, Close, false); + ErrorDialog *dlog = safenew ErrorDialog(parent, dlogTitle, message, helpURL, Close, false); dlog->CentreOnParent(); dlog->Show(); // ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak. // ANSWER-ME: This is unused. Delete it or are there plans for it? + // PRL: answer is that the parent window guarantees destruction of the dialog + // but in practice Destroy() in OnOK does that } void ShowAliasMissingDialog(AudacityProject *parent, @@ -197,7 +199,7 @@ void ShowAliasMissingDialog(AudacityProject *parent, const wxString &helpURL, const bool Close) { - ErrorDialog *dlog = new AliasedFileMissingDialog(parent, dlogTitle, message, helpURL, Close, false); + ErrorDialog *dlog = safenew AliasedFileMissingDialog(parent, dlogTitle, message, helpURL, Close, false); // Don't center because in many cases (effect, export, etc) there will be a progress bar in the center that blocks this. // instead put it just above or on the top of the project. wxPoint point; @@ -214,4 +216,6 @@ void ShowAliasMissingDialog(AudacityProject *parent, // stop playback AND read dialog's instructions. dlog->Show(); // ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak. + // PRL: answer is that the parent window guarantees destruction of the dialog + // but in practice Destroy() in OnOK does that } diff --git a/src/widgets/ExpandingToolBar.cpp b/src/widgets/ExpandingToolBar.cpp index 1765eca28..031d1d554 100644 --- a/src/widgets/ExpandingToolBar.cpp +++ b/src/widgets/ExpandingToolBar.cpp @@ -152,7 +152,7 @@ ExpandingToolBar::ExpandingToolBar(wxWindow* parent, wxColour magicColor = wxColour(0, 255, 255); ImageArray fourStates = ImageRoll::SplitV(hbar, magicColor); - mToggleButton = new AButton(this, kToggleButtonID, + mToggleButton = safenew AButton(this, kToggleButtonID, wxDefaultPosition, wxDefaultSize, ImageRoll(ImageRoll::HorizontalRoll, fourStates[0], magicColor),