Fixed a memleak in Eagle board import plugin

This commit is contained in:
Maciej Suminski 2017-07-10 11:44:56 +02:00
parent d7a4fb7d8b
commit a3fc0ef658
2 changed files with 16 additions and 3 deletions

View File

@ -144,6 +144,7 @@ EAGLE_PLUGIN::EAGLE_PLUGIN() :
EAGLE_PLUGIN::~EAGLE_PLUGIN() EAGLE_PLUGIN::~EAGLE_PLUGIN()
{ {
deleteTemplates();
delete m_rules; delete m_rules;
delete m_xpath; delete m_xpath;
} }
@ -271,8 +272,7 @@ void EAGLE_PLUGIN::init( const PROPERTIES* aProperties )
m_min_via_hole = 0; m_min_via_hole = 0;
m_xpath->clear(); m_xpath->clear();
m_pads_to_nets.clear(); m_pads_to_nets.clear();
deleteTemplates();
// m_templates.clear(); this is the FOOTPRINT cache too
m_board = NULL; m_board = NULL;
m_props = aProperties; m_props = aProperties;
@ -1648,6 +1648,16 @@ void EAGLE_PLUGIN::packageSMD( MODULE* aModule, wxXmlNode* aTree ) const
// don't know what stop, thermals, and cream should look like now. // don't know what stop, thermals, and cream should look like now.
} }
void EAGLE_PLUGIN::deleteTemplates()
{
for( auto& t : m_templates )
delete t.second;
m_templates.clear();
}
/// non-owning container /// non-owning container
typedef std::vector<ZONE_CONTAINER*> ZONES; typedef std::vector<ZONE_CONTAINER*> ZONES;
@ -2050,7 +2060,7 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
wxXmlNode* doc; wxXmlNode* doc;
LOCALE_IO toggle; // toggles on, then off, the C locale. LOCALE_IO toggle; // toggles on, then off, the C locale.
m_templates.clear(); deleteTemplates();
// Set this before completion of loading, since we rely on it for // Set this before completion of loading, since we rely on it for
// text of an exception. Delay setting m_mod_time until after successful load // text of an exception. Delay setting m_mod_time until after successful load

View File

@ -234,6 +234,9 @@ private:
void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const; void packageCircle( MODULE* aModule, wxXmlNode* aTree ) const;
void packageHole( MODULE* aModule, wxXmlNode* aTree ) const; void packageHole( MODULE* aModule, wxXmlNode* aTree ) const;
void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const; void packageSMD( MODULE* aModule, wxXmlNode* aTree ) const;
///> Deletes the footprint templates list
void deleteTemplates();
}; };
#endif // EAGLE_PLUGIN_H_ #endif // EAGLE_PLUGIN_H_