Fixed memory leaks
This commit is contained in:
parent
7e1498a46f
commit
a9efbf4716
|
@ -79,7 +79,7 @@ private:
|
||||||
wxString m_ConvertedFileName;
|
wxString m_ConvertedFileName;
|
||||||
wxSize m_frameSize;
|
wxSize m_frameSize;
|
||||||
wxPoint m_framePos;
|
wxPoint m_framePos;
|
||||||
wxConfigBase* m_config;
|
std::unique_ptr<wxConfigBase> m_config;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
||||||
|
@ -223,8 +223,6 @@ BM2CMP_FRAME::~BM2CMP_FRAME()
|
||||||
m_config->Write( KEYWORD_LAST_FORMAT, m_radioBoxFormat->GetSelection() );
|
m_config->Write( KEYWORD_LAST_FORMAT, m_radioBoxFormat->GetSelection() );
|
||||||
m_config->Write( KEYWORD_LAST_MODLAYER, m_radio_PCBLayer->GetSelection() );
|
m_config->Write( KEYWORD_LAST_MODLAYER, m_radio_PCBLayer->GetSelection() );
|
||||||
|
|
||||||
delete m_config;
|
|
||||||
|
|
||||||
/* This needed for OSX: avoids further OnDraw processing after this
|
/* This needed for OSX: avoids further OnDraw processing after this
|
||||||
* destructor and before the native window is destroyed
|
* destructor and before the native window is destroyed
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
BIN_MOD::BIN_MOD( const char* aName ) :
|
BIN_MOD::BIN_MOD( const char* aName ) :
|
||||||
m_name( aName ),
|
m_name( aName ),
|
||||||
m_config( 0 ),
|
|
||||||
m_history( 0 )
|
m_history( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -48,7 +47,7 @@ void BIN_MOD::Init()
|
||||||
Pgm().CommonSettings()->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
|
Pgm().CommonSettings()->Read( FILE_HISTORY_SIZE_KEY, &fileHistorySize, DEFAULT_FILE_HISTORY_SIZE );
|
||||||
|
|
||||||
m_history = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), ID_FILE1 );
|
m_history = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), ID_FILE1 );
|
||||||
m_history->Load( *m_config );
|
m_history->Load( *m_config.get() );
|
||||||
|
|
||||||
// Prepare On Line Help. Use only lower case for help file names, in order to
|
// Prepare On Line Help. Use only lower case for help file names, in order to
|
||||||
// avoid problems with upper/lower case file names under windows and unix.
|
// avoid problems with upper/lower case file names under windows and unix.
|
||||||
|
@ -64,14 +63,11 @@ void BIN_MOD::End()
|
||||||
{
|
{
|
||||||
if( m_config )
|
if( m_config )
|
||||||
{
|
{
|
||||||
m_history->Save( *m_config );
|
m_history->Save( *m_config.get() );
|
||||||
|
|
||||||
delete m_history;
|
delete m_history;
|
||||||
|
|
||||||
// Deleting a wxConfigBase writes its contents to disk if changed.
|
// Deleting a wxConfigBase writes its contents to disk if changed.
|
||||||
// Might be NULL if called twice, in which case nothing happens.
|
m_config.reset();
|
||||||
delete m_config;
|
|
||||||
m_config = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,15 +248,13 @@ double RoundTo0( double x, double precision )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxConfigBase* GetNewConfig( const wxString& aProgName )
|
std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName )
|
||||||
{
|
{
|
||||||
wxConfigBase* cfg = 0;
|
|
||||||
wxFileName configname;
|
wxFileName configname;
|
||||||
configname.AssignDir( GetKicadConfigPath() );
|
configname.AssignDir( GetKicadConfigPath() );
|
||||||
configname.SetFullName( aProgName );
|
configname.SetFullName( aProgName );
|
||||||
|
|
||||||
cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
|
return std::make_unique<wxConfig>( wxT( "" ), wxT( "" ), configname.GetFullPath() );
|
||||||
return cfg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,6 @@ PGM_BASE::PGM_BASE()
|
||||||
{
|
{
|
||||||
m_pgm_checker = NULL;
|
m_pgm_checker = NULL;
|
||||||
m_locale = NULL;
|
m_locale = NULL;
|
||||||
m_common_settings = NULL;
|
|
||||||
|
|
||||||
m_show_env_var_dialog = true;
|
m_show_env_var_dialog = true;
|
||||||
|
|
||||||
|
@ -173,9 +172,7 @@ PGM_BASE::~PGM_BASE()
|
||||||
void PGM_BASE::Destroy()
|
void PGM_BASE::Destroy()
|
||||||
{
|
{
|
||||||
// unlike a normal destructor, this is designed to be called more than once safely:
|
// unlike a normal destructor, this is designed to be called more than once safely:
|
||||||
|
m_common_settings.reset();
|
||||||
delete m_common_settings;
|
|
||||||
m_common_settings = 0;
|
|
||||||
|
|
||||||
delete m_pgm_checker;
|
delete m_pgm_checker;
|
||||||
m_pgm_checker = 0;
|
m_pgm_checker = 0;
|
||||||
|
@ -562,7 +559,7 @@ void PGM_BASE::loadCommonSettings()
|
||||||
// options only in pcbnew (which was the only canvas to support them). Since there's
|
// options only in pcbnew (which was the only canvas to support them). Since there's
|
||||||
// no single right answer to where to pull the common settings from, we might as well
|
// no single right answer to where to pull the common settings from, we might as well
|
||||||
// get them along with the hardware antialiasing option from pcbnew.
|
// get them along with the hardware antialiasing option from pcbnew.
|
||||||
wxConfigBase* pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
|
auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
|
||||||
wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
|
wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
|
||||||
|
|
||||||
if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
|
if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
|
||||||
|
|
|
@ -41,8 +41,8 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway,
|
||||||
m_previewItem( nullptr )
|
m_previewItem( nullptr )
|
||||||
{
|
{
|
||||||
wxString eeschemaFrameKey( SCH_EDIT_FRAME_NAME );
|
wxString eeschemaFrameKey( SCH_EDIT_FRAME_NAME );
|
||||||
wxConfigBase* eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() );
|
auto eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() );
|
||||||
m_galDisplayOptions.ReadConfig( eeschemaConfig, eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY );
|
m_galDisplayOptions.ReadConfig( eeschemaConfig.get(), eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY );
|
||||||
|
|
||||||
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType;
|
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType;
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
#include <search_stack.h>
|
#include <search_stack.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class wxConfigBase;
|
class wxConfigBase;
|
||||||
class FILE_HISTORY;
|
class FILE_HISTORY;
|
||||||
|
@ -55,7 +56,7 @@ struct BIN_MOD
|
||||||
|
|
||||||
const char* m_name; ///< name of this binary module, static C string.
|
const char* m_name; ///< name of this binary module, static C string.
|
||||||
|
|
||||||
wxConfigBase* m_config; ///< maybe from $HOME/.${m_name}
|
std::unique_ptr<wxConfigBase> m_config; ///< maybe from $HOME/.${m_name}
|
||||||
FILE_HISTORY* m_history;
|
FILE_HISTORY* m_history;
|
||||||
wxString m_help_file;
|
wxString m_help_file;
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <gal/color4d.h>
|
#include <gal/color4d.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// C++11 "polyfill" for the C++14 std::make_unique function
|
// C++11 "polyfill" for the C++14 std::make_unique function
|
||||||
#include "make_unique.h"
|
#include "make_unique.h"
|
||||||
|
@ -310,7 +311,7 @@ const wxString PrePendPath( const wxString& aEnvVar, const wxString& aPriorityPa
|
||||||
* @return A pointer to a new wxConfigBase derived object is returned. The caller is in charge
|
* @return A pointer to a new wxConfigBase derived object is returned. The caller is in charge
|
||||||
* of deleting it.
|
* of deleting it.
|
||||||
*/
|
*/
|
||||||
wxConfigBase* GetNewConfig( const wxString& aProgName );
|
std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the user configuration path used to store KiCad's configuration files.
|
* Return the user configuration path used to store KiCad's configuration files.
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
|
|
||||||
const wxString Name() { return wxString::FromUTF8( m_bm.m_name ); }
|
const wxString Name() { return wxString::FromUTF8( m_bm.m_name ); }
|
||||||
|
|
||||||
wxConfigBase* KifaceSettings() const { return m_bm.m_config; }
|
wxConfigBase* KifaceSettings() const { return m_bm.m_config.get(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function StartFlags
|
* Function StartFlags
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define PGM_BASE_H_
|
#define PGM_BASE_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <wx/filehistory.h>
|
#include <wx/filehistory.h>
|
||||||
#include <search_stack.h>
|
#include <search_stack.h>
|
||||||
|
@ -184,7 +185,7 @@ public:
|
||||||
*/
|
*/
|
||||||
VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
|
VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
|
||||||
|
|
||||||
VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
|
VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings.get(); }
|
||||||
|
|
||||||
VTBL_ENTRY void SetEditorName( const wxString& aFileName );
|
VTBL_ENTRY void SetEditorName( const wxString& aFileName );
|
||||||
|
|
||||||
|
@ -362,7 +363,7 @@ protected:
|
||||||
|
|
||||||
/// Configuration settings common to all KiCad program modules,
|
/// Configuration settings common to all KiCad program modules,
|
||||||
/// like as in $HOME/.kicad_common
|
/// like as in $HOME/.kicad_common
|
||||||
wxConfigBase* m_common_settings;
|
std::unique_ptr<wxConfigBase> m_common_settings;
|
||||||
|
|
||||||
/// full path to this program
|
/// full path to this program
|
||||||
wxString m_bin_dir;
|
wxString m_bin_dir;
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
FILE_HISTORY& GetFileHistory() { return *m_bm.m_history; }
|
FILE_HISTORY& GetFileHistory() { return *m_bm.m_history; }
|
||||||
|
|
||||||
wxConfigBase* PgmSettings() { return m_bm.m_config; }
|
wxConfigBase* PgmSettings() { return m_bm.m_config.get(); }
|
||||||
|
|
||||||
SEARCH_STACK& SysSearch() { return m_bm.m_search; }
|
SEARCH_STACK& SysSearch() { return m_bm.m_search; }
|
||||||
|
|
||||||
|
|
|
@ -83,15 +83,15 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||||
m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
|
m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
|
||||||
m_currAttenuator = m_attenuator_list[0];
|
m_currAttenuator = m_attenuator_list[0];
|
||||||
|
|
||||||
wxConfigBase* config = GetNewConfig( Pgm().App().GetAppName() );
|
auto config = GetNewConfig( Pgm().App().GetAppName() );
|
||||||
LoadSettings( config );
|
LoadSettings( config.get() );
|
||||||
|
|
||||||
ReadDataFile();
|
ReadDataFile();
|
||||||
|
|
||||||
TranslineTypeSelection( m_currTransLineType );
|
TranslineTypeSelection( m_currTransLineType );
|
||||||
m_TranslineSelection->SetSelection( m_currTransLineType );
|
m_TranslineSelection->SetSelection( m_currTransLineType );
|
||||||
|
|
||||||
TW_Init( config );
|
TW_Init( config.get() );
|
||||||
|
|
||||||
SetAttenuator( m_AttenuatorsSelection->GetSelection() );
|
SetAttenuator( m_AttenuatorsSelection->GetSelection() );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue