diff --git a/src/core/domain/system.cpp b/src/core/domain/system.cpp index bb95e16..3487d33 100644 --- a/src/core/domain/system.cpp +++ b/src/core/domain/system.cpp @@ -46,8 +46,11 @@ void System::Load(std::string module_name, std::string file_name, ImportType typ throw std::runtime_error("cannot open file: " + file_name); } - // Creation or retrieval of the module, then parse into it. + // Creation or retrieval of the module, then parse into it. add() copies the + // Part pointers into the module, which takes ownership; deleting the + // importer then frees the (now drained) Parts container, not the parts. Module *mod = mods->merge(module_name); imp->parse(mod->signals); mod->add(imp->parts()); + delete imp; } \ No newline at end of file diff --git a/src/core/imports/import_base.hpp b/src/core/imports/import_base.hpp index 04a1c28..205feb9 100644 --- a/src/core/imports/import_base.hpp +++ b/src/core/imports/import_base.hpp @@ -64,9 +64,13 @@ public: /** * @brief Virtual destructor for ImportBase. * - * Ensures proper cleanup of derived classes. + * Frees the Parts container object. Only the container is deleted, not the + * Part objects it holds: by the time the importer is destroyed those have + * been transferred to a Module (SystemElementContainer::add copies the + * pointers), which owns and deletes them. The default ~Parts frees the map + * without touching the elements, so there is no double free. */ - virtual ~ImportBase() = default; + virtual ~ImportBase() { delete prts; } }; #endif // _IMPORT_BASE_HPP_ \ No newline at end of file diff --git a/src/core/imports/import_mentor.cpp b/src/core/imports/import_mentor.cpp index 5795c4c..2bce6e4 100644 --- a/src/core/imports/import_mentor.cpp +++ b/src/core/imports/import_mentor.cpp @@ -43,16 +43,6 @@ enum class State */ ImportMentor::ImportMentor(string filename) : ImportBase(filename) {} -/** - * @brief Destructor for ImportMentor. - * - * Ensures proper cleanup by calling the base class destructor. - */ -ImportMentor::~ImportMentor() -{ - ImportBase::~ImportBase(); -} - /** * @brief Parses the file to extract parts, pins, and signals. * diff --git a/src/core/imports/import_mentor.hpp b/src/core/imports/import_mentor.hpp index 0b0f143..00029f5 100644 --- a/src/core/imports/import_mentor.hpp +++ b/src/core/imports/import_mentor.hpp @@ -10,7 +10,6 @@ class ImportMentor : public ImportBase public: ImportMentor(std::string filename); void parse(Signals *signals) override; - ~ImportMentor(); }; #endif // _IMPORT_MENTOR_HPP_ \ No newline at end of file