From 655acf9abc00118180a127f705f64077c5657e7d Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Thu, 14 Oct 2021 15:50:04 +0200 Subject: [PATCH 1/5] [App/IO] Avoid taking reference from nullptr. When the polyline vector pointer is fetched from the geo-objects in the readGLIFileV4, it can be a nullptr resulting in undefined behaviour. Instead pass the pointer to the readSurfaces functions and check there, only when necessary, for the vector pointer being a nullptr. --- Applications/FileIO/Legacy/OGSIOVer4.cpp | 42 +++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Applications/FileIO/Legacy/OGSIOVer4.cpp b/Applications/FileIO/Legacy/OGSIOVer4.cpp index 39fedc3065..d8e9aef6f9 100644 --- a/Applications/FileIO/Legacy/OGSIOVer4.cpp +++ b/Applications/FileIO/Legacy/OGSIOVer4.cpp @@ -310,7 +310,7 @@ std::string readSurface(std::istream& in, std::vector& polygon_vec, std::vector& sfc_vec, std::map& sfc_names, - const std::vector& ply_vec, + const std::vector* const ply_vec, const std::map& ply_vec_names, GeoLib::PointVec& pnt_vec, std::string const& path, std::vector& errors) @@ -367,6 +367,11 @@ std::string readSurface(std::istream& in, (line.find('#') == std::string::npos) && (line.find('$') == std::string::npos)) { + if (ply_vec == nullptr) + { + OGS_FATAL("The polyline vector is not allocated."); + } + // we did read the name of a polyline -> search the id for // polyline auto it(ply_vec_names.find(line)); @@ -376,10 +381,10 @@ std::string readSurface(std::istream& in, } else { - ply_id = ply_vec.size(); + ply_id = ply_vec->size(); } - if (ply_id == ply_vec.size()) + if (ply_id == ply_vec->size()) { WARN("readSurface(): polyline for surface not found!"); errors.emplace_back( @@ -426,20 +431,27 @@ std::string readSurface(std::istream& in, else { // surface created by polygon - if (ply_id != std::numeric_limits::max() && - ply_id != ply_vec.size()) + if (ply_id != std::numeric_limits::max()) { - if (ply_vec[ply_id]->isClosed()) + if (ply_vec == nullptr) { - polygon_vec.push_back( - new GeoLib::Polygon(*(ply_vec[ply_id]), true)); + OGS_FATAL("The polyline vector is not allocated."); } - else + + if (ply_id != ply_vec->size()) { - WARN( - "readSurface(): cannot create surface {:s} from polyline " - "{:d} since polyline is not closed.", - name, ply_id); + if ((*ply_vec)[ply_id]->isClosed()) + { + polygon_vec.push_back( + new GeoLib::Polygon(*((*ply_vec)[ply_id]), true)); + } + else + { + WARN( + "readSurface(): cannot create surface {:s} from " + "polyline {:d} since polyline is not closed.", + name, ply_id); + } } } } @@ -458,7 +470,7 @@ std::string readSurface(std::istream& in, std::string readSurfaces( std::istream& in, std::vector& sfc_vec, std::map& sfc_names, - const std::vector& ply_vec, + const std::vector* const ply_vec, const std::map& ply_vec_names, GeoLib::PointVec& pnt_vec, const std::string& path, std::vector& errors, GeoLib::GEOObjects& geo, @@ -587,7 +599,7 @@ bool readGLIFileV4(const std::string& fname, { INFO("GeoLib::readGLIFile(): read surfaces from stream."); - readSurfaces(in, sfc_vec, sfc_names, *geo.getPolylineVec(unique_name), + readSurfaces(in, sfc_vec, sfc_names, geo.getPolylineVec(unique_name), ply_names_copy, point_vec, path, errors, geo, unique_name, gmsh_path); INFO("GeoLib::readGLIFile(): \tok, {:d} surfaces read.", -- GitLab From 2c2ae93e130a4ebc2c199357549816aae9279dc3 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Sat, 16 Oct 2021 16:10:32 +0200 Subject: [PATCH 2/5] [NL] deriveBoundaryConstrainedMap returns unique_ptr This ensures the correct ownership and avoids a memory leak in VariableDependentNeumannBoundaryCondition: Direct leak of 144 byte(s) in 1 object(s) allocated from: #0 0x7f7fd1665ca1 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99 #1 0x7f7f303113e1 in NumLib::LocalToGlobalIndexMap::deriveBoundaryConstrainedMap(int, std::vector > const&, MeshLib::MeshSubset&&) const /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/NumLib/DOF/LocalToGlobalIndexMap.cpp:275 #2 0x7f7f4c74b2af in ProcessLib::createVariableDependentNeumannBoundaryCondition(BaseLib::ConfigTree const&, MeshLib::Mesh const&, NumLib::LocalToGlobalIndexMap const&, int, int, unsigned int, unsigned int, unsigned int, std::vector >, std::allocator > > > const&) /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryCondition.cpp:78 #3 0x7f7f4d80b586 in ProcessLib::createBoundaryCondition(ProcessLib::BoundaryConditionConfig const&, NumLib::LocalToGlobalIndexMap const&, MeshLib::Mesh const&, int, unsigned int, unsigned int, std::vector >, std::allocat or > > > const&, ProcessLib::Process const&) /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/BoundaryConditionAndSourceTerm/CreateBoundaryCondition.cpp:85 #4 0x7f7f4db8078f in ProcessLib::ProcessVariable::createBoundaryConditions(NumLib::LocalToGlobalIndexMap const&, int, unsigned int, std::vector >, std::allocator > > > const&, ProcessLib::Process const&) /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/ProcessVariable.cpp:221 #5 0x7f7f4db81bda in ProcessLib::BoundaryConditionCollection::addBCsForProcessVariables(std::vector, std::allocator > > const&, NumLib::LocalToGlobalIndexMap const&, unsigned int, ProcessLib::Process const&) /va r/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/BoundaryConditionAndSourceTerm/BoundaryConditionCollection.cpp:37 #6 0x7f7f4db844d3 in ProcessLib::Process::initializeProcessBoundaryConditionsAndSourceTerms(NumLib::LocalToGlobalIndexMap const&, int) /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/Process.cpp:73 #7 0x7f7f4db8ed08 in ProcessLib::Process::initializeBoundaryConditions() /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/Process.cpp:89 #8 0x7f7f4db8ed08 in ProcessLib::Process::initialize() /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/ProcessLib/Process.cpp:111 #9 0x560e7ab6e48d in main /var/lib/gitlab-runner/builds/e3EQ9HiK/0/ogs/ogs/Applications/CLI/ogs.cpp:250 #10 0x7f7f1847eb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) --- NumLib/DOF/LocalToGlobalIndexMap.cpp | 5 +++-- NumLib/DOF/LocalToGlobalIndexMap.h | 2 +- .../ConstraintDirichletBoundaryCondition.cpp | 4 ++-- .../CreateSourceTerm.cpp | 12 ++++++------ .../DeactivatedSubdomainDirichlet.cpp | 4 ++-- .../DirichletBoundaryCondition.cpp | 4 ++-- .../DirichletBoundaryConditionWithinTimeInterval.cpp | 4 ++-- .../GenericNaturalBoundaryCondition-impl.h | 4 ++-- .../NormalTractionBoundaryCondition-impl.h | 4 ++-- ...yVariableConstraintDirichletBoundaryCondition.cpp | 4 ++-- .../SolutionDependentDirichletBoundaryCondition.cpp | 4 ++-- .../VariableDependentNeumannBoundaryCondition.cpp | 7 ++++--- ...DependentNeumannBoundaryConditionLocalAssembler.h | 5 +++-- Tests/NumLib/LocalToGlobalIndexMap.cpp | 4 ++-- Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp | 8 ++++---- 15 files changed, 39 insertions(+), 36 deletions(-) diff --git a/NumLib/DOF/LocalToGlobalIndexMap.cpp b/NumLib/DOF/LocalToGlobalIndexMap.cpp index 7465e1d3ad..2f8abfbff8 100644 --- a/NumLib/DOF/LocalToGlobalIndexMap.cpp +++ b/NumLib/DOF/LocalToGlobalIndexMap.cpp @@ -233,7 +233,8 @@ LocalToGlobalIndexMap::LocalToGlobalIndexMap( } } -LocalToGlobalIndexMap* LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( +std::unique_ptr +LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( int const variable_id, std::vector const& component_ids, MeshLib::MeshSubset&& new_mesh_subset) const @@ -269,7 +270,7 @@ LocalToGlobalIndexMap* LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( } all_mesh_subsets.emplace_back(std::move(new_mesh_subset)); - return new LocalToGlobalIndexMap( + return std::make_unique( std::move(all_mesh_subsets), global_component_ids, _variable_component_offsets, elements, std::move(mesh_component_map), ConstructorTag{}); diff --git a/NumLib/DOF/LocalToGlobalIndexMap.h b/NumLib/DOF/LocalToGlobalIndexMap.h index 73ad9a138a..6f0f3c731a 100644 --- a/NumLib/DOF/LocalToGlobalIndexMap.h +++ b/NumLib/DOF/LocalToGlobalIndexMap.h @@ -92,7 +92,7 @@ public: /// Derive a LocalToGlobalIndexMap constrained to the mesh subset and mesh /// subset's elements. A new mesh component map will be constructed using /// the passed mesh_subset for the given variable and component ids. - LocalToGlobalIndexMap* deriveBoundaryConstrainedMap( + std::unique_ptr deriveBoundaryConstrainedMap( int const variable_id, std::vector const& component_ids, MeshLib::MeshSubset&& new_mesh_subset) const; diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/ConstraintDirichletBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/ConstraintDirichletBoundaryCondition.cpp index 75a20344b4..deee0186bd 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/ConstraintDirichletBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/ConstraintDirichletBoundaryCondition.cpp @@ -63,8 +63,8 @@ ConstraintDirichletBoundaryCondition::ConstraintDirichletBoundaryCondition( // Create local DOF table from intersected mesh subsets for the given // variable and component ids. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - variable_id, {component_id}, std::move(bc_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + variable_id, {component_id}, std::move(bc_mesh_subset)); auto const& bc_elements(_bc_mesh.getElements()); _local_assemblers.resize(bc_elements.size()); diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp index a31c1ce377..9ddb5e57ab 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp @@ -65,10 +65,10 @@ std::unique_ptr createSourceTerm( if (type == "Nodal") { - std::unique_ptr dof_table_source_term( + auto dof_table_source_term = dof_table_bulk.deriveBoundaryConstrainedMap( variable_id, {*config.component_id}, - std::move(source_term_mesh_subset))); + std::move(source_term_mesh_subset)); return ProcessLib::createNodalSourceTerm( config.config, config.mesh, std::move(dof_table_source_term), source_term_mesh.getID(), variable_id, *config.component_id, @@ -77,10 +77,10 @@ std::unique_ptr createSourceTerm( if (type == "Line" || type == "Volumetric") { - std::unique_ptr dof_table_source_term( + auto dof_table_source_term = dof_table_bulk.deriveBoundaryConstrainedMap( variable_id, {*config.component_id}, - std::move(source_term_mesh_subset))); + std::move(source_term_mesh_subset)); auto const& bulk_mesh_dimension = dof_table_bulk.getMeshSubset(variable_id, *config.component_id) .getMesh() @@ -94,9 +94,9 @@ std::unique_ptr createSourceTerm( if (type == "Python") { #ifdef OGS_USE_PYTHON - std::unique_ptr dof_table_source_term( + auto dof_table_source_term = dof_table_bulk.deriveBoundaryConstrainedMap( - std::move(source_term_mesh_subset))); + std::move(source_term_mesh_subset)); return ProcessLib::createPythonSourceTerm( config.config, config.mesh, std::move(dof_table_source_term), diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/DeactivatedSubdomainDirichlet.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/DeactivatedSubdomainDirichlet.cpp index f6d9a30cda..34ae8e52d8 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/DeactivatedSubdomainDirichlet.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/DeactivatedSubdomainDirichlet.cpp @@ -47,8 +47,8 @@ void DeactivatedSubdomainDirichlet::config( // Create local DOF table from the BC mesh subset for the given variable // and component id. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - _variable_id, {_component_id}, std::move(subdomain_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + _variable_id, {_component_id}, std::move(subdomain_mesh_subset)); } void DeactivatedSubdomainDirichlet::getEssentialBCValues( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryCondition.cpp index 61c37a656f..58f17b8c89 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryCondition.cpp @@ -41,8 +41,8 @@ DirichletBoundaryCondition::DirichletBoundaryCondition( // Create local DOF table from the BC mesh subset for the given variable // and component id. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - variable_id, {component_id}, std::move(bc_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + variable_id, {component_id}, std::move(bc_mesh_subset)); } void DirichletBoundaryCondition::getEssentialBCValues( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryConditionWithinTimeInterval.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryConditionWithinTimeInterval.cpp index 0061e6142a..80e0e7f43c 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryConditionWithinTimeInterval.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/DirichletBoundaryConditionWithinTimeInterval.cpp @@ -47,8 +47,8 @@ void DirichletBoundaryConditionWithinTimeInterval::config( // Create local DOF table from the BC mesh subset for the given variable // and component id. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - _variable_id, {_component_id}, std::move(bc_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + _variable_id, {_component_id}, std::move(bc_mesh_subset)); } void DirichletBoundaryConditionWithinTimeInterval::getEssentialBCValues( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/GenericNaturalBoundaryCondition-impl.h b/ProcessLib/BoundaryConditionAndSourceTerm/GenericNaturalBoundaryCondition-impl.h index 1d997e15f3..2bbda253f1 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/GenericNaturalBoundaryCondition-impl.h +++ b/ProcessLib/BoundaryConditionAndSourceTerm/GenericNaturalBoundaryCondition-impl.h @@ -62,8 +62,8 @@ GenericNaturalBoundaryCondition( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/NormalTractionBoundaryCondition-impl.h b/ProcessLib/BoundaryConditionAndSourceTerm/NormalTractionBoundaryCondition-impl.h index f74824c975..d5171a21cd 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/NormalTractionBoundaryCondition-impl.h +++ b/ProcessLib/BoundaryConditionAndSourceTerm/NormalTractionBoundaryCondition-impl.h @@ -48,8 +48,8 @@ NormalTractionBoundaryCondition:: // Create local DOF table from the BC mesh subset for the given variable and // component ids. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - variable_id, component_ids, std::move(bc_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + variable_id, component_ids, std::move(bc_mesh_subset)); BoundaryConditionAndSourceTerm::detail::createLocalAssemblers< GlobalDim, LocalAssemblerImplementation>( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/PrimaryVariableConstraintDirichletBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/PrimaryVariableConstraintDirichletBoundaryCondition.cpp index 220e13b398..5d6a0381f1 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/PrimaryVariableConstraintDirichletBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/PrimaryVariableConstraintDirichletBoundaryCondition.cpp @@ -47,8 +47,8 @@ PrimaryVariableConstraintDirichletBoundaryCondition:: // Create local DOF table from the BC mesh subset for the given variable // and component id. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - variable_id, {component_id}, std::move(bc_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + variable_id, {component_id}, std::move(bc_mesh_subset)); } void PrimaryVariableConstraintDirichletBoundaryCondition::getEssentialBCValues( diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/SolutionDependentDirichletBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/SolutionDependentDirichletBoundaryCondition.cpp index 07aa6d6821..59b5f10fac 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/SolutionDependentDirichletBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/SolutionDependentDirichletBoundaryCondition.cpp @@ -39,8 +39,8 @@ SolutionDependentDirichletBoundaryCondition:: // Create local DOF table from the BC mesh subset for the given variable // and component id. - _dof_table_boundary.reset(dof_table_bulk.deriveBoundaryConstrainedMap( - variable_id, {component_id}, std::move(bc_mesh_subset))); + _dof_table_boundary = dof_table_bulk.deriveBoundaryConstrainedMap( + variable_id, {component_id}, std::move(bc_mesh_subset)); if (bc_mesh.getProperties().existsPropertyVector(property_name)) { diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryCondition.cpp index 861b2e963a..64d5ed10f1 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryCondition.cpp @@ -74,8 +74,8 @@ createVariableDependentNeumannBoundaryCondition( std::vector const& bc_nodes = bc_mesh.getNodes(); MeshLib::MeshSubset bc_mesh_subset(bc_mesh, bc_nodes); - auto const& dof_table_boundary_other_variable = - *dof_table.deriveBoundaryConstrainedMap( + auto dof_table_boundary_other_variable = + dof_table.deriveBoundaryConstrainedMap( (variable_id + 1) % 2, {component_id}, std::move(bc_mesh_subset)); // In case of partitioned mesh the boundary could be empty, i.e. there is no @@ -97,7 +97,8 @@ createVariableDependentNeumannBoundaryCondition( component_id, global_dim, bc_mesh, VariableDependentNeumannBoundaryConditionData{ constant, coefficient_current_variable, coefficient_other_variable, - coefficient_mixed_variables, dof_table_boundary_other_variable}); + coefficient_mixed_variables, + std::move(dof_table_boundary_other_variable)}); } } // namespace ProcessLib diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryConditionLocalAssembler.h b/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryConditionLocalAssembler.h index 8866826090..495dd3ee31 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryConditionLocalAssembler.h +++ b/ProcessLib/BoundaryConditionAndSourceTerm/VariableDependentNeumannBoundaryConditionLocalAssembler.h @@ -25,7 +25,8 @@ struct VariableDependentNeumannBoundaryConditionData ParameterLib::Parameter const& coefficient_other_variable; ParameterLib::Parameter const& coefficient_mixed_variables; // Used for mapping boundary nodes to bulk nodes. - NumLib::LocalToGlobalIndexMap const& dof_table_boundary_other_variable; + std::unique_ptr + dof_table_boundary_other_variable; }; template @@ -84,7 +85,7 @@ public: auto const indices_current_variable = NumLib::getIndices(mesh_item_id, dof_table_boundary); auto const indices_other_variable = NumLib::getIndices( - mesh_item_id, _data.dof_table_boundary_other_variable); + mesh_item_id, *_data.dof_table_boundary_other_variable); std::vector const local_current_variable = x[process_id]->get(indices_current_variable); std::vector const local_other_variable = diff --git a/Tests/NumLib/LocalToGlobalIndexMap.cpp b/Tests/NumLib/LocalToGlobalIndexMap.cpp index 8d6528da15..0f19c92faa 100644 --- a/Tests/NumLib/LocalToGlobalIndexMap.cpp +++ b/Tests/NumLib/LocalToGlobalIndexMap.cpp @@ -111,10 +111,10 @@ TEST_F(NumLibLocalToGlobalIndexMapTest, DISABLED_SubsetByComponent) MeshLib::MeshSubset selected_component(*boundary_mesh, boundary_mesh->getNodes()); - auto dof_map_subset = std::unique_ptr{ + auto dof_map_subset = dof_map->deriveBoundaryConstrainedMap(1, // variable id {0}, // component id - std::move(selected_component))}; + std::move(selected_component)); // There must be as many rows as nodes in the input times the number of // components. diff --git a/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp b/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp index 314a251df7..77d0468c02 100644 --- a/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp +++ b/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp @@ -90,10 +90,10 @@ public: MeL::MeshSubset components_boundary{*mesh_items_boundary}; - dof_map_boundary.reset(dof_map->deriveBoundaryConstrainedMap( + dof_map_boundary = dof_map->deriveBoundaryConstrainedMap( 0, // variable id {selected_component}, - std::move(components_boundary))); + std::move(components_boundary)); } // Multi-component version. @@ -114,10 +114,10 @@ public: MeL::MeshSubset components_boundary{*mesh_items_boundary}; - dof_map_boundary.reset(dof_map->deriveBoundaryConstrainedMap( + dof_map_boundary = dof_map->deriveBoundaryConstrainedMap( 0, // variable id selected_components, - std::move(components_boundary))); + std::move(components_boundary)); } template -- GitLab From b21ed28f200fc5509569074ea71c076bfe1e1d74 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Sat, 11 Dec 2021 20:14:04 +0100 Subject: [PATCH 3/5] [GL] Raster; Avoid memory leak on throw. --- GeoLib/Raster.h | 1 + 1 file changed, 1 insertion(+) diff --git a/GeoLib/Raster.h b/GeoLib/Raster.h index 8fe81757d0..3c14cadb58 100644 --- a/GeoLib/Raster.h +++ b/GeoLib/Raster.h @@ -65,6 +65,7 @@ public: static_cast(std::distance(begin, end)); if (number_of_input_values != _header.n_cols * _header.n_rows) { + delete[] _raster_data; throw std::out_of_range( "Number of raster data mismatch, need " + std::to_string(_header.n_cols * _header.n_rows) + -- GitLab From 59a86cbd5d031e4e310cd470ab0281010f472a73 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Tue, 14 Dec 2021 13:18:33 +0100 Subject: [PATCH 4/5] [App/U] Avoid memory leak in generateGeometry quad --- Applications/Utils/GeoTools/generateGeometry.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Applications/Utils/GeoTools/generateGeometry.cpp b/Applications/Utils/GeoTools/generateGeometry.cpp index 2f55b02e77..ab714d56a2 100644 --- a/Applications/Utils/GeoTools/generateGeometry.cpp +++ b/Applications/Utils/GeoTools/generateGeometry.cpp @@ -85,6 +85,8 @@ std::vector generateQuadPoints( begin, end, number_of_subdivisions); quad_points.insert(quad_points.end(), intermediate_points.begin(), --intermediate_points.end()); + delete intermediate_points.back(); // Release last point, other points + // are managed by GEOObjects. }; addPointsOnLine(points[0], points[1], number_of_subdivisions_per_edge[0]); -- GitLab From 0d00566799bbad0867544ab9b01747cbb677d03b Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Tue, 14 Dec 2021 23:41:41 +0100 Subject: [PATCH 5/5] [CL] Add PhreeqcIO destructor. --- ChemistryLib/PhreeqcIO.cpp | 5 +++++ ChemistryLib/PhreeqcIO.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChemistryLib/PhreeqcIO.cpp b/ChemistryLib/PhreeqcIO.cpp index 9de2326307..2ad862e7e4 100644 --- a/ChemistryLib/PhreeqcIO.cpp +++ b/ChemistryLib/PhreeqcIO.cpp @@ -308,6 +308,11 @@ PhreeqcIO::PhreeqcIO(GlobalLinearSolver& linear_solver, } } +PhreeqcIO::~PhreeqcIO() +{ + DestroyIPhreeqc(phreeqc_instance_id); +} + void PhreeqcIO::initialize() { _num_chemical_systems = chemical_system_index_map.size(); diff --git a/ChemistryLib/PhreeqcIO.h b/ChemistryLib/PhreeqcIO.h index 5b48e35d61..c0b35908a6 100644 --- a/ChemistryLib/PhreeqcIO.h +++ b/ChemistryLib/PhreeqcIO.h @@ -43,6 +43,8 @@ public: std::unique_ptr&& dump, Knobs&& knobs); + ~PhreeqcIO(); + void initialize() override; void initializeChemicalSystemConcrete( -- GitLab