From 7674d2ba91605654454023e202b31d1cc8c5c1b6 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 24 Oct 2020 22:16:07 +0100 Subject: [PATCH] Free allocated DRC structures when re-initializing. Fixes https://gitlab.com/kicad/code/kicad/issues/6147 --- pcbnew/drc/drc_engine.cpp | 31 +++++++++++++++++++++++++++---- pcbnew/drc/drc_engine.h | 1 - pcbnew/drc/drc_test_provider.h | 3 ++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index 22499a624d..4e755ecf71 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -70,6 +70,17 @@ DRC_ENGINE::DRC_ENGINE( BOARD* aBoard, BOARD_DESIGN_SETTINGS *aSettings ) : DRC_ENGINE::~DRC_ENGINE() { + for( DRC_RULE* rule : m_rules ) + delete rule; + + for( std::pair< DRC_CONSTRAINT_TYPE_T, + std::vector* > pair : m_constraintMap ) + { + for( CONSTRAINT_WITH_CONDITIONS* constraintWithCondition : *pair.second ) + delete constraintWithCondition; + + delete pair.second; + } } @@ -484,9 +495,8 @@ void DRC_ENGINE::loadRules( const wxFileName& aPath ) void DRC_ENGINE::compileRules() { - ReportAux( wxString::Format( "Compiling Rules (%d rules, %d conditions): ", - (int) m_rules.size(), - (int) m_ruleConditions.size() ) ); + ReportAux( wxString::Format( "Compiling Rules (%d rules): ", + (int) m_rules.size() ) ); for( DRC_TEST_PROVIDER* provider : m_testProviders ) { @@ -569,10 +579,23 @@ void DRC_ENGINE::InitEngine( const wxFileName& aRulePath ) provider->SetDRCEngine( this ); } - m_ruleConditions.clear(); + for( DRC_RULE* rule : m_rules ) + delete rule; + m_rules.clear(); m_rulesValid = false; + for( std::pair< DRC_CONSTRAINT_TYPE_T, + std::vector* > pair : m_constraintMap ) + { + for( CONSTRAINT_WITH_CONDITIONS* constraintWithCondition : *pair.second ) + delete constraintWithCondition; + + delete pair.second; + } + + m_constraintMap.clear(); + try // attempt to load full set of rules (implicit + user rules) { loadImplicitRules(); diff --git a/pcbnew/drc/drc_engine.h b/pcbnew/drc/drc_engine.h index 3b23eac6da..565b23ee31 100644 --- a/pcbnew/drc/drc_engine.h +++ b/pcbnew/drc/drc_engine.h @@ -213,7 +213,6 @@ protected: KIGFX::WS_PROXY_VIEW_ITEM* m_worksheet; NETLIST* m_schematicNetlist; - std::vector m_ruleConditions; std::vector m_rules; bool m_rulesValid; std::vector m_testProviders; diff --git a/pcbnew/drc/drc_test_provider.h b/pcbnew/drc/drc_test_provider.h index 193de93025..b3343881ec 100644 --- a/pcbnew/drc/drc_test_provider.h +++ b/pcbnew/drc/drc_test_provider.h @@ -78,6 +78,7 @@ public: void SetDRCEngine( DRC_ENGINE *engine ) { m_drcEngine = engine; + m_stats.clear(); } /** @@ -126,7 +127,7 @@ protected: DRC_ENGINE* m_drcEngine; std::unordered_map m_stats; bool m_isRuleDriven = true; - bool m_enabled = true; + bool m_enabled = true; wxString m_msg; // Allocating strings gets expensive enough to want to avoid it };