improved memory liberation (explicitly set to NULL after delete)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15933 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Gilles Depeyrot
2002-06-23 17:22:54 +00:00
parent d208e6412a
commit f5bb225133
20 changed files with 140 additions and 80 deletions

View File

@@ -104,16 +104,19 @@ BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
EVT_CHOICE(-1, wxComboBoxChoice::OnChoice)
END_EVENT_TABLE()
wxComboBox::~wxComboBox()
{
// delete the controls now, don't leave them alive even though they woudl
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
if (m_text != NULL) {
delete m_text;
m_text = NULL;
}
if (m_choice != NULL) {
delete m_choice;
m_choice = NULL;
}
}

View File

@@ -253,7 +253,10 @@ wxString wxDir::GetName() const
wxDir::~wxDir()
{
if (M_DIR != NULL) {
delete M_DIR;
m_data = NULL;
}
}
// ----------------------------------------------------------------------------

View File

@@ -141,8 +141,10 @@ wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID i
wxGLCanvas::~wxGLCanvas()
{
if (m_glContext)
if (m_glContext != NULL) {
delete m_glContext;
m_glContext = NULL;
}
}
static AGLPixelFormat ChoosePixelFormat(const int *attribList)

View File

@@ -265,6 +265,7 @@ void wxListBox::Free()
size_t uiCount = m_aItems.Count();
while ( uiCount-- != 0 ) {
delete m_aItems[uiCount];
m_aItems[uiCount] = NULL;
}
m_aItems.Clear();
@@ -373,6 +374,7 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
size_t ui = m_aItems.Count();
while ( ui-- != 0 ) {
delete m_aItems[ui];
m_aItems[ui] = NULL;
}
m_aItems.Empty();

View File

@@ -36,7 +36,10 @@ wxPaletteRefData::wxPaletteRefData()
wxPaletteRefData::~wxPaletteRefData()
{
if (m_palette != NULL) {
delete[] m_palette ;
m_palette = NULL;
}
}
wxPalette::wxPalette()

View File

@@ -111,12 +111,11 @@ wxPNGReader::Create(int width, int height, int depth, int colortype)
Width = width; Height = height; Depth = depth;
ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
delete m_palette;
delete[] RawImage ;
RawImage = 0;
m_palette = 0;
m_palette = NULL;
delete[] RawImage;
RawImage = NULL;
if (lpbi)
{
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
}
lpbi = wxMacCreateGWorld( Width , Height , Depth);
@@ -134,11 +133,18 @@ wxPNGReader::Create(int width, int height, int depth, int colortype)
wxPNGReader::~wxPNGReader ( )
{
if (RawImage != NULL) {
delete[] RawImage ;
RawImage = NULL;
}
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
lpbi = NULL;
}
if (m_palette != NULL) {
delete m_palette;
m_palette = NULL;
}
}
@@ -260,10 +266,12 @@ void wxPNGReader::NullData()
{
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
}
delete m_palette;
lpbi = NULL;
}
if (m_palette != NULL) {
delete m_palette;
m_palette = NULL;
}
}
wxBitmap* wxPNGReader::GetBitmap(void)
@@ -432,7 +440,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName)
if (!info_ptr)
{
fclose(fp);
delete(png_ptr);
delete png_ptr;
return FALSE;
}
/* set error handling */
@@ -440,8 +448,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName)
{
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
fclose(fp);
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* If we get here, we had a problem reading the file */
return FALSE;
@@ -623,8 +631,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName)
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
/* free the structures */
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* close the file */
fclose(fp);
@@ -663,7 +671,7 @@ bool wxPNGReader::SaveFile(char * ImageFileName)
if (!info_ptr)
{
fclose(fp);
delete(png_ptr);
delete png_ptr;
return FALSE;
}
@@ -672,8 +680,8 @@ bool wxPNGReader::SaveFile(char * ImageFileName)
{
png_write_destroy(png_ptr);
fclose(fp);
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* If we get here, we had a problem reading the file */
return FALSE;
@@ -770,8 +778,8 @@ bool wxPNGReader::SaveFile(char * ImageFileName)
delete[] (info_ptr->palette);
/* free the structures */
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* close the file */
fclose(fp);

View File

@@ -71,8 +71,10 @@ bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
wxPrintDialog::~wxPrintDialog()
{
if (m_destroyDC && m_printerDC)
if (m_destroyDC && m_printerDC) {
delete m_printerDC;
m_printerDC = NULL;
}
}
int wxPrintDialog::ShowModal()

View File

@@ -99,7 +99,7 @@ public:
{
if ( m_locked > 0 )
{
wxLogDebug(_T("Warning: freeing a locked mutex (%d locks)."), m_locked);
wxLogDebug(_T("Warning: freeing a locked mutex (%ld locks)."), m_locked);
}
}
@@ -576,7 +576,10 @@ wxThread::wxThread(wxThreadKind kind)
wxThread::~wxThread()
{
s_threads.Remove( (void*) this ) ;
if (m_internal != NULL) {
delete m_internal;
m_internal = NULL;
}
}
// create/start thread

View File

@@ -92,8 +92,10 @@ bool wxTimer::IsRunning() const
wxTimer::~wxTimer()
{
Stop();
if (m_info != NULL) {
delete m_info ;
m_info = NULL ;
}
int index = gTimersInProcess.Index( this ) ;
if ( index != wxNOT_FOUND )
gTimersInProcess.RemoveAt( index ) ;

View File

@@ -201,8 +201,10 @@ void wxMacToolTip::Setup( WindowRef win , wxString text , wxPoint localPosition
wxMacToolTip::~wxMacToolTip()
{
if ( m_timer )
if ( m_timer ) {
delete m_timer ;
m_timer = NULL;
}
if ( m_backpict )
Clear() ;
}

View File

@@ -104,16 +104,19 @@ BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
EVT_CHOICE(-1, wxComboBoxChoice::OnChoice)
END_EVENT_TABLE()
wxComboBox::~wxComboBox()
{
// delete the controls now, don't leave them alive even though they woudl
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
if (m_text != NULL) {
delete m_text;
m_text = NULL;
}
if (m_choice != NULL) {
delete m_choice;
m_choice = NULL;
}
}

View File

@@ -253,7 +253,10 @@ wxString wxDir::GetName() const
wxDir::~wxDir()
{
if (M_DIR != NULL) {
delete M_DIR;
m_data = NULL;
}
}
// ----------------------------------------------------------------------------

View File

@@ -141,8 +141,10 @@ wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID i
wxGLCanvas::~wxGLCanvas()
{
if (m_glContext)
if (m_glContext != NULL) {
delete m_glContext;
m_glContext = NULL;
}
}
static AGLPixelFormat ChoosePixelFormat(const int *attribList)

View File

@@ -265,6 +265,7 @@ void wxListBox::Free()
size_t uiCount = m_aItems.Count();
while ( uiCount-- != 0 ) {
delete m_aItems[uiCount];
m_aItems[uiCount] = NULL;
}
m_aItems.Clear();
@@ -373,6 +374,7 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
size_t ui = m_aItems.Count();
while ( ui-- != 0 ) {
delete m_aItems[ui];
m_aItems[ui] = NULL;
}
m_aItems.Empty();

View File

@@ -36,7 +36,10 @@ wxPaletteRefData::wxPaletteRefData()
wxPaletteRefData::~wxPaletteRefData()
{
if (m_palette != NULL) {
delete[] m_palette ;
m_palette = NULL;
}
}
wxPalette::wxPalette()

View File

@@ -111,12 +111,11 @@ wxPNGReader::Create(int width, int height, int depth, int colortype)
Width = width; Height = height; Depth = depth;
ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0);
delete m_palette;
delete[] RawImage ;
RawImage = 0;
m_palette = 0;
m_palette = NULL;
delete[] RawImage;
RawImage = NULL;
if (lpbi)
{
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
}
lpbi = wxMacCreateGWorld( Width , Height , Depth);
@@ -134,11 +133,18 @@ wxPNGReader::Create(int width, int height, int depth, int colortype)
wxPNGReader::~wxPNGReader ( )
{
if (RawImage != NULL) {
delete[] RawImage ;
RawImage = NULL;
}
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
lpbi = NULL;
}
if (m_palette != NULL) {
delete m_palette;
m_palette = NULL;
}
}
@@ -260,10 +266,12 @@ void wxPNGReader::NullData()
{
if (lpbi) {
wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
}
delete m_palette;
lpbi = NULL;
}
if (m_palette != NULL) {
delete m_palette;
m_palette = NULL;
}
}
wxBitmap* wxPNGReader::GetBitmap(void)
@@ -432,7 +440,7 @@ bool wxPNGReader::ReadFile(char * ImageFileName)
if (!info_ptr)
{
fclose(fp);
delete(png_ptr);
delete png_ptr;
return FALSE;
}
/* set error handling */
@@ -440,8 +448,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName)
{
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
fclose(fp);
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* If we get here, we had a problem reading the file */
return FALSE;
@@ -623,8 +631,8 @@ bool wxPNGReader::ReadFile(char * ImageFileName)
png_read_destroy(png_ptr, info_ptr, (png_info *)0);
/* free the structures */
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* close the file */
fclose(fp);
@@ -663,7 +671,7 @@ bool wxPNGReader::SaveFile(char * ImageFileName)
if (!info_ptr)
{
fclose(fp);
delete(png_ptr);
delete png_ptr;
return FALSE;
}
@@ -672,8 +680,8 @@ bool wxPNGReader::SaveFile(char * ImageFileName)
{
png_write_destroy(png_ptr);
fclose(fp);
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* If we get here, we had a problem reading the file */
return FALSE;
@@ -770,8 +778,8 @@ bool wxPNGReader::SaveFile(char * ImageFileName)
delete[] (info_ptr->palette);
/* free the structures */
delete(png_ptr);
delete(info_ptr);
delete png_ptr;
delete info_ptr;
/* close the file */
fclose(fp);

View File

@@ -71,8 +71,10 @@ bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
wxPrintDialog::~wxPrintDialog()
{
if (m_destroyDC && m_printerDC)
if (m_destroyDC && m_printerDC) {
delete m_printerDC;
m_printerDC = NULL;
}
}
int wxPrintDialog::ShowModal()

View File

@@ -99,7 +99,7 @@ public:
{
if ( m_locked > 0 )
{
wxLogDebug(_T("Warning: freeing a locked mutex (%d locks)."), m_locked);
wxLogDebug(_T("Warning: freeing a locked mutex (%ld locks)."), m_locked);
}
}
@@ -576,7 +576,10 @@ wxThread::wxThread(wxThreadKind kind)
wxThread::~wxThread()
{
s_threads.Remove( (void*) this ) ;
if (m_internal != NULL) {
delete m_internal;
m_internal = NULL;
}
}
// create/start thread

View File

@@ -92,8 +92,10 @@ bool wxTimer::IsRunning() const
wxTimer::~wxTimer()
{
Stop();
if (m_info != NULL) {
delete m_info ;
m_info = NULL ;
}
int index = gTimersInProcess.Index( this ) ;
if ( index != wxNOT_FOUND )
gTimersInProcess.RemoveAt( index ) ;

View File

@@ -201,8 +201,10 @@ void wxMacToolTip::Setup( WindowRef win , wxString text , wxPoint localPosition
wxMacToolTip::~wxMacToolTip()
{
if ( m_timer )
if ( m_timer ) {
delete m_timer ;
m_timer = NULL;
}
if ( m_backpict )
Clear() ;
}