From 2174fda88d813ef7e2f232386b9b88a4ce5c7645 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sat, 28 Jan 2023 14:19:03 +0100 Subject: [PATCH] #2704 keep track of simple types by iden to free later --- src/ifcparse/IfcFile.h | 3 +++ src/ifcparse/IfcParse.cpp | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index c36d77a30f..90d6ef4073 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -74,6 +74,7 @@ class IFC_PARSE_API IfcFile { public: typedef std::map entities_by_type_t; typedef boost::unordered_map entity_by_id_t; + typedef boost::unordered_map entity_by_iden_t; typedef std::map entity_by_guid_t; typedef std::tuple inverse_attr_record; enum INVERSE_ATTR { INSTANCE_ID, INSTANCE_TYPE, ATTRIBUTE_INDEX }; @@ -133,6 +134,8 @@ private: std::vector internal_attribute_vector_, internal_attribute_vector_simple_type_; entity_by_id_t byid; + // this is for simple types + entity_by_iden_t byidentity; entities_by_type_t bytype; entities_by_type_t bytype_excl; entities_by_ref_t byref; diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 44d5ef2b9a..54f58189fa 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -985,6 +985,7 @@ EntityArgument::~EntityArgument() { // For that purpose when parsed, the simple type instance is explicitly added to the // file. The reason is we want parsed simply types to behave the same as constructed // simple types. + // delete entity; } @@ -1877,8 +1878,13 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id) // See whether the instance is already part of a file if (entity->data().file != 0) { if (entity->data().file == this) { + if (!entity->declaration().as_entity()) { + // While not a mapping that can be queried, we do need to free the instance later on + byidentity[new_entity->identity()] = new_entity; + } + // If it is part of this file - // nothing needs to be done. + // nothing else needs to be done. return entity; } @@ -2082,6 +2088,9 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id) // pointer has to be set, so that actual copies are created in subsequent // times. new_entity->data().file = this; + + // While not a mapping that can be queried, we do need to free the instance + byidentity[new_entity->identity()] = new_entity; } if (parsing_complete_ && ty->as_entity()) { @@ -2371,7 +2380,7 @@ IfcFile::~IfcFile() { for (const auto& pair : byid) { entities_to_delete.insert(pair.second); } - for (const auto& pair : entity_file_map) { + for (const auto& pair : byidentity) { entities_to_delete.insert(pair.second); } for (auto entity : entities_to_delete) {