From 6d4c78288c59076f88f006379509472935d78d4d Mon Sep 17 00:00:00 2001 From: heister Date: Thu, 23 Jan 2014 17:26:42 +0000 Subject: [PATCH] fix invalid memory access caused by undefined order of construction of static members (found with ASAN) git-svn-id: https://svn.dealii.org/trunk@32289 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/hp/mapping_collection.h | 17 ++++++++--------- deal.II/source/hp/mapping_collection.cc | 11 ++++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/deal.II/include/deal.II/hp/mapping_collection.h b/deal.II/include/deal.II/hp/mapping_collection.h index 512a6872b4..117d76bee0 100644 --- a/deal.II/include/deal.II/hp/mapping_collection.h +++ b/deal.II/include/deal.II/hp/mapping_collection.h @@ -148,16 +148,15 @@ namespace hp { private: /** - * A static MappingQ1 - * object. We can't use the one - * in ::StaticMappingQ1 since - * we can't make sure that the - * constructor for that object - * is run before the - * constructor for the present - * static object. + * A static MappingQ1 object. We can't use the one in ::StaticMappingQ1 + * since we can't make sure that the constructor for that object is run + * before we want to use the object (when constructing mapping_collection + * below). Therefore we create a helper function which returns a + * reference to a static object that will be constructed the first time + * this function is called. */ - static MappingQ1 mapping_q1; + static + MappingQ1& return_static_mapping_q1(); public: /** diff --git a/deal.II/source/hp/mapping_collection.cc b/deal.II/source/hp/mapping_collection.cc index 0d9fdcfa83..eb59d77463 100644 --- a/deal.II/source/hp/mapping_collection.cc +++ b/deal.II/source/hp/mapping_collection.cc @@ -82,16 +82,17 @@ namespace hp //--------------------------------------------------------------------------- - template - MappingQ1 - StaticMappingQ1::mapping_q1; - + MappingQ1& StaticMappingQ1::return_static_mapping_q1() + { + static MappingQ1 mapping; + return mapping; + } template MappingCollection StaticMappingQ1::mapping_collection - = MappingCollection(mapping_q1); + = MappingCollection(StaticMappingQ1::return_static_mapping_q1()); } -- 2.39.5