[glom] Remove unnecessary checks before use of delete.



commit 09c84e90153b72ee85009448f281a902db4c3f48
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Dec 16 14:06:53 2010 +0100

    Remove unnecessary checks before use of delete.
    
    * glom/application.cc:
    * glom/bakery/app_withdoc.cc:
    * glom/bakery/app_withdoc_gtk.cc:
    * glom/frame_glom.cc:
    * glom/libglom/connectionpool.cc:
    * glom/libglom/data_structure/layout/layoutitem.cc:
    * glom/libglom/sharedptr.h:
    * glom/libglom/test_avahi_publisher.cc:
    * glom/mode_data/box_data_portal.cc:
    * glom/mode_data/datawidget/combochoiceswithtreemodel.cc:
    * glom/mode_data/flowtablewithfields.cc:
    * glom/mode_data/notebook_data.cc: C++ doesn't mind if we call delete on a
    null pointer. Found by cppcheck.

 ChangeLog                                          |   18 +++++
 glom/application.cc                                |   69 +++++-------------
 glom/bakery/app_withdoc.cc                         |    7 +-
 glom/bakery/app_withdoc_gtk.cc                     |   21 ++----
 glom/frame_glom.cc                                 |   79 ++++++--------------
 glom/libglom/connectionpool.cc                     |   14 +---
 glom/libglom/data_structure/layout/layoutitem.cc   |    3 +-
 glom/libglom/sharedptr.h                           |    7 +-
 glom/libglom/test_avahi_publisher.cc               |    3 +-
 glom/mode_data/box_data_portal.cc                  |    6 +-
 .../mode_data/datawidget/combo_as_radio_buttons.cc |    4 +-
 .../datawidget/combochoiceswithtreemodel.cc        |    3 +-
 glom/mode_data/flowtablewithfields.cc              |    7 +-
 glom/mode_data/notebook_data.cc                    |    3 +-
 14 files changed, 83 insertions(+), 161 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2574a2c..cfd4886 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-12-16  Murray Cumming  <murrayc murrayc com>
+
+	Remove unnecessary checks before use of delete.
+
+	* glom/application.cc:
+	* glom/bakery/app_withdoc.cc:
+	* glom/bakery/app_withdoc_gtk.cc:
+	* glom/frame_glom.cc:
+	* glom/libglom/connectionpool.cc:
+	* glom/libglom/data_structure/layout/layoutitem.cc:
+	* glom/libglom/sharedptr.h:
+	* glom/libglom/test_avahi_publisher.cc:
+	* glom/mode_data/box_data_portal.cc:
+	* glom/mode_data/datawidget/combochoiceswithtreemodel.cc:
+	* glom/mode_data/flowtablewithfields.cc:
+	* glom/mode_data/notebook_data.cc: C++ doesn't mind if we call delete on a 
+	null pointer. Found by cppcheck.
+
 2010-12-15  Ben Konrath  <ben bagu org>
 
 	Add Eclipse 3.6 / CDT 7.0 configuration files.
diff --git a/glom/application.cc b/glom/application.cc
index e96796c..5a004da 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -126,30 +126,16 @@ Application::~Application()
     delete m_window_translations;
   }
 
-  if(m_avahi_progress_dialog)
-  {
-    delete m_avahi_progress_dialog;
-    m_avahi_progress_dialog = 0;
-  }
+  delete m_avahi_progress_dialog;
+  m_avahi_progress_dialog = 0;
 
+  delete m_dialog_progress_creating;
+  m_dialog_progress_creating = 0;
 
-  if(m_dialog_progress_creating)
-  {
-    delete m_dialog_progress_creating;
-    m_dialog_progress_creating = 0;
-  }
+  delete m_dialog_progess_save_backup;
 
-  if(m_dialog_progess_save_backup)
-  {
-    delete m_dialog_progess_save_backup;
-    m_dialog_progess_save_backup = 0;
-  }
-
-  if(m_dialog_progess_convert_backup)
-  {
-    delete m_dialog_progess_convert_backup;
-    m_dialog_progess_convert_backup = 0;
-  }
+  delete m_dialog_progess_convert_backup;
+  m_dialog_progess_convert_backup = 0;
   #endif // !GLOM_ENABLE_CLIENT_ONLY
 
   #ifdef GLOM_ENABLE_MAEMO
@@ -164,11 +150,8 @@ Application::~Application()
 void Application::on_connection_avahi_begin()
 {
   //Create the dialog:
-  if(m_avahi_progress_dialog)
-  {
-    delete m_avahi_progress_dialog;
-    m_avahi_progress_dialog = 0;
-  }
+  delete m_avahi_progress_dialog;
+  m_avahi_progress_dialog = 0;
 
   m_avahi_progress_dialog = new Gtk::MessageDialog(Utils::bold_message(_("Glom: Generating Encryption Certificates")), true, Gtk::MESSAGE_INFO);
   m_avahi_progress_dialog->set_secondary_text(_("Please wait while Glom prepares your system for publishing over the network."));
@@ -186,11 +169,7 @@ void Application::on_connection_avahi_progress()
 void Application::on_connection_avahi_done()
 {
   //Delete the dialog:
-  if(m_avahi_progress_dialog)
-  {
-    delete m_avahi_progress_dialog;
-    m_avahi_progress_dialog = 0;
-  }
+  delete m_avahi_progress_dialog;
 }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
@@ -2024,11 +2003,8 @@ bool Application::recreate_database_from_backup(const Glib::ustring& backup_uri,
   const bool restored = connection_pool->convert_backup(
     sigc::mem_fun(*this, &Application::on_connection_convert_backup_progress), original_dir_path);
 
-  if(m_dialog_progess_convert_backup)
-  {
-    delete m_dialog_progess_convert_backup;
-    m_dialog_progess_convert_backup = 0;
-  }
+  delete m_dialog_progess_convert_backup;
+  m_dialog_progess_convert_backup = 0;
 
   if(!restored)
   {
@@ -2775,11 +2751,8 @@ void Application::on_menu_developer_export_backup()
     ConnectionPool* connection_pool = ConnectionPool::get_instance();
     saved = connection_pool->save_backup(sigc::mem_fun(*this, &Application::on_connection_save_backup_progress), path_dir);
 
-    if(m_dialog_progess_save_backup)
-    {
-      delete m_dialog_progess_save_backup;
-      m_dialog_progess_save_backup = 0;
-    }
+    delete m_dialog_progess_save_backup;
+    m_dialog_progess_save_backup = 0;
   }
 
   //Compress the backup in a .tar.gz, so it is slightly more safe from changes:
@@ -2822,11 +2795,8 @@ void Application::on_menu_developer_export_backup()
         std::cerr << G_STRFUNC << "tar failed with command:" << command_tar << std::endl;
       }
 
-      if(m_dialog_progess_save_backup)
-      {
-        delete m_dialog_progess_save_backup;
-        m_dialog_progess_save_backup = 0;
-      }
+      delete m_dialog_progess_save_backup;
+      m_dialog_progess_save_backup = 0;
     }
   }
 
@@ -2914,11 +2884,8 @@ bool Application::do_restore_backup(const Glib::ustring& backup_uri)
     std::cerr << G_STRFUNC << ": tar failed with command:" << command_tar << std::endl;
   }
 
-  if(m_dialog_progess_convert_backup)
-  {
-    delete m_dialog_progess_convert_backup;
-    m_dialog_progess_convert_backup = 0;
-  }
+  delete m_dialog_progess_convert_backup;
+  m_dialog_progess_convert_backup = 0;
 
   if(!untarred)
     ui_warning(_("Restore Backup failed."), _("There was an error while restoring the backup. The tar utility failed to extract the archive."));
diff --git a/glom/bakery/app_withdoc.cc b/glom/bakery/app_withdoc.cc
index b94351b..5dc768e 100644
--- a/glom/bakery/app_withdoc.cc
+++ b/glom/bakery/app_withdoc.cc
@@ -38,11 +38,8 @@ App_WithDoc::App_WithDoc(const Glib::ustring& appname)
 App_WithDoc::~App_WithDoc()
 {
   //Delete the document:
-  if(m_pDocument)
-  {
-    delete m_pDocument; //This will cause Document::signal_forget to be emitted, so the Views will then null their pointers as well. A smartpointer might be a better way to do this.
-    m_pDocument = 0;
-  }
+  delete m_pDocument; //This will cause Document::signal_forget to be emitted, so the Views will then null their pointers as well. A smartpointer might be a better way to do this.
+  m_pDocument = 0;
 }
 
 //static
diff --git a/glom/bakery/app_withdoc_gtk.cc b/glom/bakery/app_withdoc_gtk.cc
index a73983d..dee1e0f 100644
--- a/glom/bakery/app_withdoc_gtk.cc
+++ b/glom/bakery/app_withdoc_gtk.cc
@@ -71,17 +71,11 @@ App_WithDoc_Gtk::App_WithDoc_Gtk(BaseObjectType* cobject, const Glib::ustring& a
   
 App_WithDoc_Gtk::~App_WithDoc_Gtk()
 {
-  if(m_pVBox)
-  {
-    delete m_pVBox;
-    m_pVBox = 0;
-  }
+  delete m_pVBox;
+  m_pVBox = 0;
   
-  if(m_pAbout)
-  {
-    delete m_pAbout;
-    m_pAbout = 0;
-  }
+  delete m_pAbout;
+  m_pAbout = 0;
 }
 
 
@@ -412,11 +406,8 @@ void App_WithDoc_Gtk::on_menu_help_about()
   else
   {
     //Re-create About box:
-    if(m_pAbout)
-    {
-      delete m_pAbout;
-      m_pAbout = 0;
-    }
+    delete m_pAbout;
+    m_pAbout = 0;
 
     Gtk::AboutDialog* pDerived = new Gtk::AboutDialog;
     m_pAbout = pDerived;
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 6f702ea..2f3887a 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -208,11 +208,8 @@ Frame_Glom::~Frame_Glom()
   if(m_pBox_Tables)
     remove_view(m_pBox_Tables);
 
-  if(m_pDialog_Tables)
-  {
-    delete m_pDialog_Tables;
-    m_pDialog_Tables = 0;
-  }
+  delete m_pDialog_Tables;
+  m_pDialog_Tables = 0;
 #endif //GLOM_ENABLE_MAEMO
 
   remove_view(&m_Notebook_Data); //Also a composite view.
@@ -227,24 +224,15 @@ Frame_Glom::~Frame_Glom()
   }
 
 
-  if(m_dialog_progess_connection_startup)
-  {
-    delete m_dialog_progess_connection_startup;
-    m_dialog_progess_connection_startup = 0;
-  }
+  delete m_dialog_progess_connection_startup;
+  m_dialog_progess_connection_startup = 0;
 
-  if(m_dialog_progess_connection_cleanup)
-  {
-    delete m_dialog_progess_connection_cleanup;
-    m_dialog_progess_connection_cleanup = 0;
-  }
+  delete m_dialog_progess_connection_cleanup;
+  m_dialog_progess_connection_cleanup = 0;
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
-  if(m_dialog_progess_connection_initialize)
-  {
-    delete m_dialog_progess_connection_initialize;
-    m_dialog_progess_connection_initialize = 0;
-  }
+  delete m_dialog_progess_connection_initialize;
+  m_dialog_progess_connection_initialize = 0;
 
   if(m_pBox_Reports)
     remove_view(m_pBox_Reports);
@@ -1111,11 +1099,8 @@ void Frame_Glom::on_menu_file_toggle_share(const Glib::RefPtr<Gtk::ToggleAction>
 
     connectionpool->cleanup( sigc::mem_fun(*this, &Frame_Glom::on_connection_cleanup_progress) );
 
-    if(m_dialog_progess_connection_cleanup)
-    {
-      delete m_dialog_progess_connection_cleanup;
-      m_dialog_progess_connection_cleanup = 0;
-    }
+    delete m_dialog_progess_connection_cleanup;
+    m_dialog_progess_connection_cleanup = 0;
 
     connectionpool->set_network_shared(sigc::mem_fun(*this, &Frame_Glom::on_connection_startup_progress), shared);
     ConnectionPool::StartupErrors started = connectionpool->startup( sigc::mem_fun(*this, &Frame_Glom::on_connection_startup_progress) );
@@ -1127,11 +1112,8 @@ void Frame_Glom::on_menu_file_toggle_share(const Glib::RefPtr<Gtk::ToggleAction>
 
     connectionpool->set_ready_to_connect();
 
-    if(m_dialog_progess_connection_startup)
-    {
-      delete m_dialog_progess_connection_startup;
-      m_dialog_progess_connection_startup = 0;
-    }
+    delete m_dialog_progess_connection_startup;
+    m_dialog_progess_connection_startup = 0;
   }
 
   //Update the UI:
@@ -2099,11 +2081,8 @@ bool Frame_Glom::connection_request_password_and_choose_new_database_name()
       const bool initialized = handle_connection_initialize_errors( connection_pool->initialize(
         sigc::mem_fun(*this, &Frame_Glom::on_connection_initialize_progress) ) );
 
-      if(m_dialog_progess_connection_initialize)
-      {
-        delete m_dialog_progess_connection_initialize;
-        m_dialog_progess_connection_initialize = 0;
-      }
+      delete m_dialog_progess_connection_initialize;
+      m_dialog_progess_connection_initialize = 0;
 
       if(!initialized)
         return false;
@@ -2178,11 +2157,8 @@ bool Frame_Glom::connection_request_password_and_choose_new_database_name()
     return false;
   }
 
-  if(m_dialog_progess_connection_startup)
-  {
-    delete m_dialog_progess_connection_startup;
-    m_dialog_progess_connection_startup = 0;
-  }
+  delete m_dialog_progess_connection_startup;
+  m_dialog_progess_connection_startup = 0;
 
   const Glib::ustring database_name = document->get_connection_database();
 
@@ -2288,11 +2264,8 @@ void Frame_Glom::cleanup_connection()
   ConnectionPool* connection_pool = ConnectionPool::get_instance();
   connection_pool->cleanup( sigc::mem_fun(*this, &Frame_Glom::on_connection_cleanup_progress) );
 
-  if(m_dialog_progess_connection_cleanup)
-  {
-    delete m_dialog_progess_connection_cleanup;
-    m_dialog_progess_connection_cleanup = 0;
-  }
+  delete m_dialog_progess_connection_cleanup;
+  m_dialog_progess_connection_cleanup = 0;
 }
 
 bool Frame_Glom::handle_request_password_connection_error(bool asked_for_password, const ExceptionConnection& ex, bool& database_not_found)
@@ -2346,11 +2319,8 @@ bool Frame_Glom::connection_request_password_and_attempt(bool& database_not_foun
     return false;
   }
 
-  if(m_dialog_progess_connection_startup)
-  {
-    delete m_dialog_progess_connection_startup;
-    m_dialog_progess_connection_startup = 0;
-  }
+  delete m_dialog_progess_connection_startup;
+  m_dialog_progess_connection_startup = 0;
 
   //Only ask for the password if we are shared on the network, or we are using a centrally hosted server.
   //Otherwise, no password question is necessary, due to how our self-hosted database server is configured.
@@ -2358,11 +2328,8 @@ bool Frame_Glom::connection_request_password_and_attempt(bool& database_not_foun
     || document->get_hosting_mode() == Document::HOSTING_MODE_POSTGRES_CENTRAL)
   {
     //We recreate the dialog each time to make sure it is clean of any changes:
-    if(m_pDialogConnection)
-    {
-      delete m_pDialogConnection;
-      m_pDialogConnection = 0;
-    }
+    delete m_pDialogConnection;
+    m_pDialogConnection = 0;
 
     Utils::get_glade_widget_derived_with_warning(m_pDialogConnection);
     add_view(m_pDialogConnection); //Also a composite view.
@@ -2380,7 +2347,7 @@ bool Frame_Glom::connection_request_password_and_attempt(bool& database_not_foun
     if(!known_password.empty())
       m_pDialogConnection->set_password(known_password);
   }
-  else if(m_pDialogConnection)
+  else
   {
     //Later, if m_pDialogConnection is null then we assume we should use the known user/password:
     delete m_pDialogConnection;
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index b052340..5f1fe1a 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -113,11 +113,8 @@ ConnectionPool::ConnectionPool()
 
 ConnectionPool::~ConnectionPool()
 {
-  if(m_pFieldTypes)
-  {
-    delete m_pFieldTypes;
-    m_pFieldTypes = 0;
-  }
+  delete m_pFieldTypes;
+  m_pFieldTypes = 0;
 }
 
 //static
@@ -177,11 +174,8 @@ void ConnectionPool::setup_from_document(const Document* document)
 
 void ConnectionPool::delete_instance()
 {
-  if(m_instance)
-  {
-    delete m_instance;
-    m_instance = 0;
-  }
+  delete m_instance;
+  m_instance = 0;
 }
 
 bool ConnectionPool::get_ready_to_connect() const
diff --git a/glom/libglom/data_structure/layout/layoutitem.cc b/glom/libglom/data_structure/layout/layoutitem.cc
index 95e1b0b..436af3b 100644
--- a/glom/libglom/data_structure/layout/layoutitem.cc
+++ b/glom/libglom/data_structure/layout/layoutitem.cc
@@ -91,8 +91,7 @@ LayoutItem& LayoutItem::operator=(const LayoutItem& src)
   m_editable = src.m_editable;
   m_display_width = src.m_display_width;
 
-  if(m_positions)
-    delete m_positions;
+  delete m_positions;
   m_positions = 0;
 
   if(src.m_positions)
diff --git a/glom/libglom/sharedptr.h b/glom/libglom/sharedptr.h
index 336c5f4..8075820 100644
--- a/glom/libglom/sharedptr.h
+++ b/glom/libglom/sharedptr.h
@@ -369,11 +369,8 @@ void sharedptr<T_obj>::unref()
     //Unalloc if this is the last user of the obj:
     if(*m_pRefCount == 0)
     {
-      if(m_pobj)
-      {
-        delete m_pobj;
-        m_pobj = 0;
-      }
+      delete m_pobj;
+      m_pobj = 0;
 
        //Clear ref count:
        delete m_pRefCount;
diff --git a/glom/libglom/test_avahi_publisher.cc b/glom/libglom/test_avahi_publisher.cc
index 8db0682..20cd500 100644
--- a/glom/libglom/test_avahi_publisher.cc
+++ b/glom/libglom/test_avahi_publisher.cc
@@ -44,8 +44,7 @@ TestWindow::TestWindow()
 
 TestWindow::~TestWindow()
 {
-  if(m_avahi_publisher)
-    delete m_avahi_publisher;
+  delete m_avahi_publisher;
 }
 
 void TestWindow::on_button_start()
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index 08e4a41..429b5ba 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -72,8 +72,7 @@ Box_Data_Portal::Box_Data_Portal()
 Box_Data_Portal::~Box_Data_Portal()
 {
   #ifdef GLOM_ENABLE_MAEMO
-  if(m_window_maemo_details)
-    delete m_window_maemo_details;
+  delete m_window_maemo_details;
 
   if(m_box_maemo_details)
   {
@@ -128,8 +127,7 @@ void Box_Data_Portal::on_maemo_appmenubutton_add()
   if(!m_portal)
     return;
 
-  if(m_window_maemo_details)
-    delete m_window_maemo_details;
+  delete m_window_maemo_details;
 
   if(m_box_maemo_details)
   {
diff --git a/glom/mode_data/datawidget/combo_as_radio_buttons.cc b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
index 84be03c..931a280 100644
--- a/glom/mode_data/datawidget/combo_as_radio_buttons.cc
+++ b/glom/mode_data/datawidget/combo_as_radio_buttons.cc
@@ -161,8 +161,8 @@ ComboAsRadioButtons::~ComboAsRadioButtons()
   for(type_map_buttons::iterator iter = m_map_buttons.begin();
     iter != m_map_buttons.end(); ++iter)
   {
-     Gtk::RadioButton* button = iter->second;
-     delete button;
+    Gtk::RadioButton* button = iter->second;
+    delete button;
   }
   m_map_buttons.clear();
 }
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index ed89da0..2fcf74e 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -80,8 +80,7 @@ void ComboChoicesWithTreeModel::delete_model()
   for(type_vec_model_columns_fixed::iterator iter = m_vec_model_columns_fixed.begin(); iter != m_vec_model_columns_fixed.end(); ++iter)
   {
     type_model_column_fixed* model_column = *iter;
-     if(model_column)
-       delete model_column;
+    delete model_column;
   }
   m_vec_model_columns_fixed.clear();
 
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 3b0747a..2f0dd2e 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -672,11 +672,8 @@ void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_
 void FlowTableWithFields::add_placeholder_at_position(const sharedptr<LayoutItem_Placeholder>& /* layoutitem_placeholder */, const Glib::ustring& /* table_name */, const type_list_layoutwidgets::iterator& add_before)
 {
   //Delete any existing placeholder (there can be only one):
-  if(m_placeholder)
-  {
-    delete m_placeholder;
-    m_placeholder = 0;
-  }
+  delete m_placeholder;
+  m_placeholder = 0;
 
   //Add the widget:
   m_placeholder = Gtk::manage(new Gtk::Alignment());
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index 5cd33a4..b5d96f3 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -111,8 +111,7 @@ Notebook_Data::~Notebook_Data()
   remove_view(&m_Box_Details);
 
 #ifdef GLOM_ENABLE_MAEMO
-  if(m_window_maemo_details)
-    delete m_window_maemo_details;
+  delete m_window_maemo_details;
 #endif //GLOM_ENABLE_MAEMO
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]