Remove redundant checks for NULL before calling delete

This commit is contained in:
Paul Cornett 2020-02-02 23:51:39 -08:00
parent 05183b7099
commit 0ca45d1a59
23 changed files with 39 additions and 75 deletions

View File

@ -1213,7 +1213,7 @@ public:
const wxIcon &GetIcon() const
{ return m_icon; }
void SetData( wxClientData *data )
{ if (m_data) delete m_data; m_data = data; }
{ delete m_data; m_data = data; }
wxClientData *GetData() const
{ return m_data; }

View File

@ -144,7 +144,7 @@ public:
wxDataObject *GetDataObject() const
{ return m_dataObject; }
void SetDataObject(wxDataObject *dataObject)
{ if (m_dataObject) delete m_dataObject;
{ delete m_dataObject;
m_dataObject = dataObject; }
// these functions are called when data is moved over position (x, y) and

View File

@ -53,7 +53,7 @@ class WXDLLIMPEXP_BASE wxEncodingConverter : public wxObject
public:
wxEncodingConverter();
virtual ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
virtual ~wxEncodingConverter() { delete[] m_Table; }
// Initialize conversion. Both output or input encoding may
// be wxFONTENCODING_UNICODE.

View File

@ -40,9 +40,7 @@ void wxClientDataContainer::DoSetClientObject( wxClientData *data )
wxASSERT_MSG( m_clientDataType != wxClientData_Void,
wxT("can't have both object and void client data") );
if ( m_clientObject )
delete m_clientObject;
delete m_clientObject;
m_clientObject = data;
m_clientDataType = wxClientData_Object;
}

View File

@ -107,8 +107,7 @@ wxPrintData::~wxPrintData()
if (m_nativeData->m_ref == 0)
delete m_nativeData;
if (m_privData)
delete [] m_privData;
delete[] m_privData;
}
void wxPrintData::ConvertToNative()

View File

@ -170,8 +170,7 @@ void wxItemContainer::SetClientObject(unsigned int n, wxClientData *data)
{
wxClientData * clientDataOld =
static_cast<wxClientData *>(DoGetItemClientData(n));
if ( clientDataOld )
delete clientDataOld;
delete clientDataOld;
}
else // didn't have any client data so far
{

View File

@ -2485,8 +2485,7 @@ wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
{
if (m_data)
delete m_data;
delete m_data;
}
wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(

View File

@ -1919,8 +1919,7 @@ void wxEvtHandler::DoSetClientObject( wxClientData *data )
wxASSERT_MSG( m_clientDataType != wxClientData_Void,
wxT("can't have both object and void client data") );
if ( m_clientObject )
delete m_clientObject;
delete m_clientObject;
m_clientObject = data;
m_clientDataType = wxClientData_Object;

View File

@ -407,8 +407,7 @@ wxFontMapperBase::wxFontMapperBase()
wxFontMapperBase::~wxFontMapperBase()
{
#if wxUSE_CONFIG && wxUSE_FILECONFIG
if ( m_configDummy )
delete m_configDummy;
delete m_configDummy;
#endif // wxUSE_CONFIG
}

View File

@ -87,10 +87,7 @@ wxFileSystemWatcherBase::wxFileSystemWatcherBase() :
wxFileSystemWatcherBase::~wxFileSystemWatcherBase()
{
RemoveAll();
if (m_service)
{
delete m_service;
}
delete m_service;
}
bool wxFileSystemWatcherBase::Add(const wxFileName& path, int events)

View File

@ -182,11 +182,9 @@ wxSizerItem* wxGridBagSizer::Add( wxWindow *window,
wxGBSizerItem* item = new wxGBSizerItem(window, pos, span, flag, border, userData);
if ( Add(item) )
return item;
else
{
delete item;
return NULL;
}
delete item;
return NULL;
}
wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer,
@ -196,11 +194,9 @@ wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer,
wxGBSizerItem* item = new wxGBSizerItem(sizer, pos, span, flag, border, userData);
if ( Add(item) )
return item;
else
{
delete item;
return NULL;
}
delete item;
return NULL;
}
wxSizerItem* wxGridBagSizer::Add( int width, int height,
@ -210,11 +206,9 @@ wxSizerItem* wxGridBagSizer::Add( int width, int height,
wxGBSizerItem* item = new wxGBSizerItem(width, height, pos, span, flag, border, userData);
if ( Add(item) )
return item;
else
{
delete item;
return NULL;
}
delete item;
return NULL;
}
wxSizerItem* wxGridBagSizer::Add( wxGBSizerItem *item )

View File

@ -269,8 +269,7 @@ const wxClassInfo* wxMediaCtrl::NextBackend(wxClassInfo::const_iterator* it)
//---------------------------------------------------------------------------
wxMediaCtrl::~wxMediaCtrl()
{
if (m_imp)
delete m_imp;
delete m_imp;
}
//---------------------------------------------------------------------------

View File

@ -290,8 +290,7 @@ wxFileType::wxFileType()
wxFileType::~wxFileType()
{
if ( m_impl )
delete m_impl;
delete m_impl;
}
bool wxFileType::GetExtensions(wxArrayString& extensions)
@ -589,8 +588,7 @@ wxMimeTypesManager::wxMimeTypesManager()
wxMimeTypesManager::~wxMimeTypesManager()
{
if ( m_impl )
delete m_impl;
delete m_impl;
}
bool wxMimeTypesManager::Unassociate(wxFileType *ft)

View File

@ -85,9 +85,7 @@ wxPrintFactory *wxPrintFactory::m_factory = NULL;
void wxPrintFactory::SetPrintFactory( wxPrintFactory *factory )
{
if (wxPrintFactory::m_factory)
delete wxPrintFactory::m_factory;
delete wxPrintFactory::m_factory;
wxPrintFactory::m_factory = factory;
}
@ -1873,12 +1871,9 @@ void wxPrintPreviewBase::Init(wxPrintout *printout,
wxPrintPreviewBase::~wxPrintPreviewBase()
{
if (m_previewPrintout)
delete m_previewPrintout;
if (m_previewBitmap)
delete m_previewBitmap;
if (m_printPrintout)
delete m_printPrintout;
delete m_previewPrintout;
delete m_previewBitmap;
delete m_printPrintout;
}
bool wxPrintPreviewBase::SetCurrentPage(int pageNum)

View File

@ -1782,11 +1782,7 @@ wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
#if wxUSE_CARET
void wxWindowBase::SetCaret(wxCaret *caret)
{
if ( m_caret )
{
delete m_caret;
}
delete m_caret;
m_caret = caret;
if ( m_caret )
@ -1804,8 +1800,7 @@ void wxWindowBase::SetCaret(wxCaret *caret)
void wxWindowBase::SetValidator(const wxValidator& validator)
{
if ( m_windowValidator )
delete m_windowValidator;
delete m_windowValidator;
m_windowValidator = static_cast<wxValidator *>(validator.Clone());
@ -2321,9 +2316,7 @@ void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
{
if ( m_tooltip != tooltip )
{
if ( m_tooltip )
delete m_tooltip;
delete m_tooltip;
m_tooltip = tooltip;
}
}

View File

@ -1454,7 +1454,7 @@ wxFileIconsTable::~wxFileIconsTable()
WX_CLEAR_HASH_TABLE(*m_HashTable);
delete m_HashTable;
}
if (m_smallImageList) delete m_smallImageList;
delete m_smallImageList;
}
// delayed initialization - wait until first use (wxArtProv not created yet)

View File

@ -58,10 +58,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxGenericDragImage, wxObject);
wxGenericDragImage::~wxGenericDragImage()
{
if (m_windowDC)
{
delete m_windowDC;
}
delete m_windowDC;
}
void wxGenericDragImage::Init()

View File

@ -100,7 +100,7 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
// May have pressed cancel.
if (!dc || !dc->IsOk())
{
if (dc) delete dc;
delete dc;
sm_lastError = wxPRINTER_ERROR;
return false;
}

View File

@ -5777,7 +5777,7 @@ void wxWindowGTK::SetDropTarget( wxDropTarget *dropTarget )
if (m_dropTarget) m_dropTarget->GtkUnregisterWidget( dnd_widget );
if (m_dropTarget) delete m_dropTarget;
delete m_dropTarget;
m_dropTarget = dropTarget;
if (m_dropTarget) m_dropTarget->GtkRegisterWidget( dnd_widget );

View File

@ -605,15 +605,15 @@ wxHtmlHelpWindow::~wxHtmlHelpWindow()
// PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
if (m_DataCreated)
delete m_Data;
if (m_NormalFonts) delete m_NormalFonts;
if (m_FixedFonts) delete m_FixedFonts;
delete m_NormalFonts;
delete m_FixedFonts;
if (m_PagesHash)
{
WX_CLEAR_HASH_TABLE(*m_PagesHash);
delete m_PagesHash;
}
#if wxUSE_PRINTING_ARCHITECTURE
if (m_Printer) delete m_Printer;
delete m_Printer;
#endif
}

View File

@ -757,8 +757,7 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
cel->SetId(tag.GetParam(wxT("id"))); // may be empty
cel->SetAlt(tag.GetParam(wxT("alt")));
m_WParser->GetContainer()->InsertCell(cel);
if (str)
delete str;
delete str;
}
}
if (tag.GetName() == wxT("MAP"))

View File

@ -304,7 +304,7 @@ wxDialUpManagerImpl::wxDialUpManagerImpl()
wxDialUpManagerImpl::~wxDialUpManagerImpl()
{
if(m_timer) delete m_timer;
delete m_timer;
if(m_DialProcess)
{
m_DialProcess->Disconnect();

View File

@ -703,8 +703,7 @@ wxInotifyFileSystemWatcher::wxInotifyFileSystemWatcher(const wxFileName& path,
{
if (!Init())
{
if (m_service)
delete m_service;
delete m_service;
return;
}