]> git.saurik.com Git - wxWidgets.git/commitdiff
improved memory liberation (explicitly set to NULL after delete)
authorGilles Depeyrot <gilles_depeyrot@mac.com>
Sun, 23 Jun 2002 17:22:54 +0000 (17:22 +0000)
committerGilles Depeyrot <gilles_depeyrot@mac.com>
Sun, 23 Jun 2002 17:22:54 +0000 (17:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15933 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

20 files changed:
src/mac/carbon/combobox.cpp
src/mac/carbon/dirmac.cpp
src/mac/carbon/glcanvas.cpp
src/mac/carbon/listbox.cpp
src/mac/carbon/palette.cpp
src/mac/carbon/pnghand.cpp
src/mac/carbon/printdlg.cpp
src/mac/carbon/thread.cpp
src/mac/carbon/timer.cpp
src/mac/carbon/tooltip.cpp
src/mac/combobox.cpp
src/mac/dirmac.cpp
src/mac/glcanvas.cpp
src/mac/listbox.cpp
src/mac/palette.cpp
src/mac/pnghand.cpp
src/mac/printdlg.cpp
src/mac/thread.cpp
src/mac/timer.cpp
src/mac/tooltip.cpp

index db47c86aaaddaea953e3bc4d3bff996240806bbc..e67e1d9601b56859d03035a4fb9c7009450fdf87 100644 (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
-    delete m_text;
-    delete m_choice;
+    if (m_text != NULL) {
+        delete m_text;
+        m_text = NULL;
+    }
+    if (m_choice != NULL) {
+        delete m_choice;
+        m_choice = NULL;
+    }
 }
 
 
index 1acff5b7cab2b48900b3886c1644f9ebc0f49768..729be9473d485e1699b8fb4c09169bc19040e297 100644 (file)
@@ -253,7 +253,10 @@ wxString wxDir::GetName() const
 
 wxDir::~wxDir()
 {
-    delete M_DIR;
+    if (M_DIR != NULL) {
+        delete M_DIR;
+        m_data = NULL;
+    }
 }
 
 // ----------------------------------------------------------------------------
index 62d9c307c44a67542b3859f67957d993cb0f1fbe..16e47d4c79ad0685a24ecca6adb156e8360775da 100644 (file)
@@ -141,8 +141,10 @@ wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID i
 
 wxGLCanvas::~wxGLCanvas()
 {
-  if (m_glContext)
-    delete m_glContext;
+    if (m_glContext != NULL) {
+        delete m_glContext;
+        m_glContext = NULL;
+    }
 }
 
 static AGLPixelFormat ChoosePixelFormat(const int *attribList)
index 2d8471f00e9bb4ab7a72014bcc9356ced57698f3..2d9a8708d13acb0de831308f2c5c8072c7da1d6a 100644 (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();
 
index 1c18196135861acd9c20f81456b50ce4ef9b34dd..c847131f4021a64d2d4e3cd5f6d5520e0add2a1e 100644 (file)
@@ -36,7 +36,10 @@ wxPaletteRefData::wxPaletteRefData()
 
 wxPaletteRefData::~wxPaletteRefData()
 {
-       delete[] m_palette ;
+    if (m_palette != NULL) {
+        delete[] m_palette ;
+        m_palette = NULL;
+    }
 }
 
 wxPalette::wxPalette()
index 1ebf612f17bd978188e9f4811e1780bc4f1d7bdb..3d2690803c0779d77e550a6cf9d8e0a3e31fc2bc 100644 (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 ( )
 {
-       delete[] RawImage ;
-  if (lpbi)  {
+    if (RawImage != NULL) {
+        delete[] RawImage ;
+        RawImage = NULL;
+    }
+    if (lpbi)  {
        wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
-  }
-  delete m_palette;
+        lpbi = NULL;
+    }
+    if (m_palette != NULL) {
+        delete m_palette;
+        m_palette = NULL;
+    }
 }
 
 
@@ -260,10 +266,12 @@ void wxPNGReader::NullData()
 {
   if (lpbi)  {
        wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
+        lpbi = NULL;
+  }
+  if (m_palette != NULL) {
+      delete m_palette;
+      m_palette = NULL;
   }
-  delete m_palette;
-  lpbi = NULL;
-  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);
index adb620e76f4c602ef12da3f168ad81b07edba336..ec13b9745533f2553212d8034d8396b6ebe47442 100644 (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()
index 5ce510da31c00c056283c9405bb9bb9777a483f5..5ea6f21f32161da7e3e231648f847f60dab88611 100644 (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 ) ;
-    delete m_internal;
+    if (m_internal != NULL) {
+        delete m_internal;
+        m_internal = NULL;
+    }
 }
 
 // create/start thread
index debf409696d5561a77b8c80641c114dae41320ba..2355b8eaceba62af11fa3374cd65982502eebf22 100644 (file)
@@ -92,8 +92,10 @@ bool wxTimer::IsRunning() const
 wxTimer::~wxTimer()
 {
     Stop();
-    delete m_info ;
-    m_info = NULL ;
+    if (m_info != NULL) {
+        delete m_info ;
+        m_info = NULL ;
+    }
     int index = gTimersInProcess.Index( this ) ;
     if ( index != wxNOT_FOUND )
         gTimersInProcess.RemoveAt( index ) ;  
index c4eea989d6892895527e98d72421e268275f351d..ba6de8cc8a1c9123730510e71ac752e5eaf7ce68 100644 (file)
@@ -201,10 +201,12 @@ void wxMacToolTip::Setup( WindowRef win  , wxString text , wxPoint localPosition
 
 wxMacToolTip::~wxMacToolTip() 
 {
-    if ( m_timer )
+    if ( m_timer ) {
         delete m_timer ;
-       if ( m_backpict ) 
-               Clear() ;
+        m_timer = NULL;
+    }
+    if ( m_backpict ) 
+        Clear() ;
 }
 
 const short kTipBorder = 2 ;
index db47c86aaaddaea953e3bc4d3bff996240806bbc..e67e1d9601b56859d03035a4fb9c7009450fdf87 100644 (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
-    delete m_text;
-    delete m_choice;
+    if (m_text != NULL) {
+        delete m_text;
+        m_text = NULL;
+    }
+    if (m_choice != NULL) {
+        delete m_choice;
+        m_choice = NULL;
+    }
 }
 
 
index 1acff5b7cab2b48900b3886c1644f9ebc0f49768..729be9473d485e1699b8fb4c09169bc19040e297 100644 (file)
@@ -253,7 +253,10 @@ wxString wxDir::GetName() const
 
 wxDir::~wxDir()
 {
-    delete M_DIR;
+    if (M_DIR != NULL) {
+        delete M_DIR;
+        m_data = NULL;
+    }
 }
 
 // ----------------------------------------------------------------------------
index 62d9c307c44a67542b3859f67957d993cb0f1fbe..16e47d4c79ad0685a24ecca6adb156e8360775da 100644 (file)
@@ -141,8 +141,10 @@ wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID i
 
 wxGLCanvas::~wxGLCanvas()
 {
-  if (m_glContext)
-    delete m_glContext;
+    if (m_glContext != NULL) {
+        delete m_glContext;
+        m_glContext = NULL;
+    }
 }
 
 static AGLPixelFormat ChoosePixelFormat(const int *attribList)
index 2d8471f00e9bb4ab7a72014bcc9356ced57698f3..2d9a8708d13acb0de831308f2c5c8072c7da1d6a 100644 (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();
 
index 1c18196135861acd9c20f81456b50ce4ef9b34dd..c847131f4021a64d2d4e3cd5f6d5520e0add2a1e 100644 (file)
@@ -36,7 +36,10 @@ wxPaletteRefData::wxPaletteRefData()
 
 wxPaletteRefData::~wxPaletteRefData()
 {
-       delete[] m_palette ;
+    if (m_palette != NULL) {
+        delete[] m_palette ;
+        m_palette = NULL;
+    }
 }
 
 wxPalette::wxPalette()
index 1ebf612f17bd978188e9f4811e1780bc4f1d7bdb..3d2690803c0779d77e550a6cf9d8e0a3e31fc2bc 100644 (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 ( )
 {
-       delete[] RawImage ;
-  if (lpbi)  {
+    if (RawImage != NULL) {
+        delete[] RawImage ;
+        RawImage = NULL;
+    }
+    if (lpbi)  {
        wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
-  }
-  delete m_palette;
+        lpbi = NULL;
+    }
+    if (m_palette != NULL) {
+        delete m_palette;
+        m_palette = NULL;
+    }
 }
 
 
@@ -260,10 +266,12 @@ void wxPNGReader::NullData()
 {
   if (lpbi)  {
        wxMacDestroyGWorld( (GWorldPtr) lpbi ) ;
+        lpbi = NULL;
+  }
+  if (m_palette != NULL) {
+      delete m_palette;
+      m_palette = NULL;
   }
-  delete m_palette;
-  lpbi = NULL;
-  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);
index adb620e76f4c602ef12da3f168ad81b07edba336..ec13b9745533f2553212d8034d8396b6ebe47442 100644 (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()
index 5ce510da31c00c056283c9405bb9bb9777a483f5..5ea6f21f32161da7e3e231648f847f60dab88611 100644 (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 ) ;
-    delete m_internal;
+    if (m_internal != NULL) {
+        delete m_internal;
+        m_internal = NULL;
+    }
 }
 
 // create/start thread
index debf409696d5561a77b8c80641c114dae41320ba..2355b8eaceba62af11fa3374cd65982502eebf22 100644 (file)
@@ -92,8 +92,10 @@ bool wxTimer::IsRunning() const
 wxTimer::~wxTimer()
 {
     Stop();
-    delete m_info ;
-    m_info = NULL ;
+    if (m_info != NULL) {
+        delete m_info ;
+        m_info = NULL ;
+    }
     int index = gTimersInProcess.Index( this ) ;
     if ( index != wxNOT_FOUND )
         gTimersInProcess.RemoveAt( index ) ;  
index c4eea989d6892895527e98d72421e268275f351d..ba6de8cc8a1c9123730510e71ac752e5eaf7ce68 100644 (file)
@@ -201,10 +201,12 @@ void wxMacToolTip::Setup( WindowRef win  , wxString text , wxPoint localPosition
 
 wxMacToolTip::~wxMacToolTip() 
 {
-    if ( m_timer )
+    if ( m_timer ) {
         delete m_timer ;
-       if ( m_backpict ) 
-               Clear() ;
+        m_timer = NULL;
+    }
+    if ( m_backpict ) 
+        Clear() ;
 }
 
 const short kTipBorder = 2 ;