Fixed a memory corruption issue from the Netlist destructor.

This commit is contained in:
Matthias Koefferlein 2018-12-31 17:33:14 +01:00
parent 37d8f0bfca
commit 060abc056e
2 changed files with 29 additions and 1 deletions

View File

@ -555,11 +555,23 @@ Circuit::Circuit (const Circuit &other)
m_net_by_name (this, &Circuit::begin_nets, &Circuit::end_nets), m_net_by_name (this, &Circuit::begin_nets, &Circuit::end_nets),
m_index (0) m_index (0)
{ {
operator= (other);
m_devices.changed ().add (this, &Circuit::devices_changed); m_devices.changed ().add (this, &Circuit::devices_changed);
m_nets.changed ().add (this, &Circuit::nets_changed); m_nets.changed ().add (this, &Circuit::nets_changed);
m_subcircuits.changed ().add (this, &Circuit::subcircuits_changed); m_subcircuits.changed ().add (this, &Circuit::subcircuits_changed);
}
operator= (other); Circuit::~Circuit ()
{
m_devices.changed ().remove (this, &Circuit::devices_changed);
m_nets.changed ().remove (this, &Circuit::nets_changed);
m_subcircuits.changed ().remove (this, &Circuit::subcircuits_changed);
// the default destructor will make the nets access "this" to unregister the
// objects - hence we have to do this explicitly.
m_nets.clear ();
m_subcircuits.clear ();
m_devices.clear ();
} }
Circuit &Circuit::operator= (const Circuit &other) Circuit &Circuit::operator= (const Circuit &other)
@ -1201,6 +1213,12 @@ Netlist::Netlist (const Netlist &other)
m_circuits.changed ().add (this, &Netlist::circuits_changed); m_circuits.changed ().add (this, &Netlist::circuits_changed);
} }
Netlist::~Netlist ()
{
m_circuits.changed ().remove (this, &Netlist::invalidate_topology);
m_circuits.changed ().remove (this, &Netlist::circuits_changed);
}
Netlist &Netlist::operator= (const Netlist &other) Netlist &Netlist::operator= (const Netlist &other)
{ {
if (this != &other) { if (this != &other) {

View File

@ -1043,6 +1043,11 @@ public:
*/ */
Circuit (const Circuit &other); Circuit (const Circuit &other);
/**
* @brief Destructor
*/
~Circuit ();
/** /**
* @brief Assignment * @brief Assignment
*/ */
@ -2005,6 +2010,11 @@ public:
*/ */
Netlist (const Netlist &other); Netlist (const Netlist &other);
/**
* @brief Destructor
*/
~Netlist ();
/** /**
* @brief Assignment * @brief Assignment
*/ */