From 467b8369024f0f44b25f1c98ef384fb42f2832e2 Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 25 Oct 2006 03:09:22 +0000 Subject: [PATCH] Use shared_ptr's instead of plain C-style pointers, to ensure that the factory objects get deleted at the end of the program and don't show up as memory leaks when running under valgrind. git-svn-id: https://svn.dealii.org/trunk@14085 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/source/fe/fe_tools.cc | 49 +++++++++++++++------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/deal.II/deal.II/source/fe/fe_tools.cc b/deal.II/deal.II/source/fe/fe_tools.cc index 82aefc0b5b..633b9042e8 100644 --- a/deal.II/deal.II/source/fe/fe_tools.cc +++ b/deal.II/deal.II/source/fe/fe_tools.cc @@ -50,39 +50,46 @@ DEAL_II_NAMESPACE_OPEN namespace { + // a shared pointer to factory + // objects, to ensure that they get + // deleted at the end of the + // program run and don't end up as + // apparent memory leaks to + // programs like valgrind + typedef + boost::shared_ptr > + FEFactoryPointer; + // a function that returns the // default set of finite element // names and factory objects for // them. used to initialize // fe_name_map below - std::map * > + std::map get_default_fe_names () { - std::map * > - default_map; + std::map default_map; default_map["FE_Q_Hierarchical"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_ABF"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_RaviartThomas"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_RaviartThomasNodal"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_Nedelec"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_DGPNonparametric"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_DGP"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_DGPMonomial"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_DGQ"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); default_map["FE_Q"] - = new FETools::FEFactory >; + = FEFactoryPointer(new FETools::FEFactory >); return default_map; } @@ -116,7 +123,7 @@ namespace // there are no thread-safety // issues here std::map * > + boost::shared_ptr > > fe_name_map = get_default_fe_names (); } @@ -1480,7 +1487,7 @@ FETools::add_fe_name(const std::string& parameter_name, // Insert the normalized name into // the map - fe_name_map[name] = factory; + fe_name_map[name] = FEFactoryPointer(factory); } @@ -1734,10 +1741,8 @@ FETools::get_fe_from_name_aux (std::string &name) // is just adding an element Threads::ThreadMutex::ScopedLock lock (fe_name_map_lock); - typename std::map*> - ::const_iterator - entry = fe_name_map.find(name_part); - AssertThrow (entry != fe_name_map.end(), ExcInvalidFEName(name)); + AssertThrow (fe_name_map.find(name_part) != fe_name_map.end(), + ExcInvalidFEName(name)); // Now, just the (degree) // part should be left. if (name.size() == 0 || name[0] != '(') @@ -1746,7 +1751,7 @@ FETools::get_fe_from_name_aux (std::string &name) const std::pair tmp = Utilities::get_integer_at_position (name, 0); name.erase(0, tmp.second+1); - return entry->second->get(tmp.first); + return fe_name_map.find(name_part)->second->get(tmp.first); } -- 2.39.5