Fixed memory leaks

This commit is contained in:
Maciej Suminski 2018-12-11 16:21:21 +01:00
parent 7e1498a46f
commit a9efbf4716
11 changed files with 22 additions and 30 deletions

View File

@ -79,7 +79,7 @@ private:
wxString m_ConvertedFileName;
wxSize m_frameSize;
wxPoint m_framePos;
wxConfigBase* m_config;
std::unique_ptr<wxConfigBase> m_config;
public:
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_MODLAYER, m_radio_PCBLayer->GetSelection() );
delete m_config;
/* This needed for OSX: avoids further OnDraw processing after this
* destructor and before the native window is destroyed
*/

View File

@ -29,7 +29,6 @@
BIN_MOD::BIN_MOD( const char* aName ) :
m_name( aName ),
m_config( 0 ),
m_history( 0 )
{
}
@ -48,7 +47,7 @@ void BIN_MOD::Init()
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->Load( *m_config );
m_history->Load( *m_config.get() );
// 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.
@ -64,14 +63,11 @@ void BIN_MOD::End()
{
if( m_config )
{
m_history->Save( *m_config );
m_history->Save( *m_config.get() );
delete m_history;
// Deleting a wxConfigBase writes its contents to disk if changed.
// Might be NULL if called twice, in which case nothing happens.
delete m_config;
m_config = 0;
m_config.reset();
}
}

View File

@ -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;
configname.AssignDir( GetKicadConfigPath() );
configname.SetFullName( aProgName );
cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
return cfg;
return std::make_unique<wxConfig>( wxT( "" ), wxT( "" ), configname.GetFullPath() );
}

View File

@ -154,7 +154,6 @@ PGM_BASE::PGM_BASE()
{
m_pgm_checker = NULL;
m_locale = NULL;
m_common_settings = NULL;
m_show_env_var_dialog = true;
@ -173,9 +172,7 @@ PGM_BASE::~PGM_BASE()
void PGM_BASE::Destroy()
{
// unlike a normal destructor, this is designed to be called more than once safely:
delete m_common_settings;
m_common_settings = 0;
m_common_settings.reset();
delete m_pgm_checker;
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
// 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.
wxConfigBase* pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )

View File

@ -41,8 +41,8 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway,
m_previewItem( nullptr )
{
wxString eeschemaFrameKey( SCH_EDIT_FRAME_NAME );
wxConfigBase* eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() );
m_galDisplayOptions.ReadConfig( eeschemaConfig, eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY );
auto eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() );
m_galDisplayOptions.ReadConfig( eeschemaConfig.get(), eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY );
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType;

View File

@ -33,6 +33,7 @@
#include <wx/string.h>
#include <search_stack.h>
#include <memory>
class wxConfigBase;
class FILE_HISTORY;
@ -55,7 +56,7 @@ struct BIN_MOD
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;
wxString m_help_file;

View File

@ -43,6 +43,7 @@
#include <gal/color4d.h>
#include <atomic>
#include <memory>
// C++11 "polyfill" for the C++14 std::make_unique function
#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
* 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.

View File

@ -100,7 +100,7 @@ public:
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

View File

@ -32,6 +32,7 @@
#define PGM_BASE_H_
#include <map>
#include <memory>
#include <wx/filename.h>
#include <wx/filehistory.h>
#include <search_stack.h>
@ -184,7 +185,7 @@ public:
*/
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 );
@ -362,7 +363,7 @@ protected:
/// Configuration settings common to all KiCad program modules,
/// like as in $HOME/.kicad_common
wxConfigBase* m_common_settings;
std::unique_ptr<wxConfigBase> m_common_settings;
/// full path to this program
wxString m_bin_dir;

View File

@ -56,7 +56,7 @@ public:
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; }

View File

@ -83,15 +83,15 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
m_currAttenuator = m_attenuator_list[0];
wxConfigBase* config = GetNewConfig( Pgm().App().GetAppName() );
LoadSettings( config );
auto config = GetNewConfig( Pgm().App().GetAppName() );
LoadSettings( config.get() );
ReadDataFile();
TranslineTypeSelection( m_currTransLineType );
m_TranslineSelection->SetSelection( m_currTransLineType );
TW_Init( config );
TW_Init( config.get() );
SetAttenuator( m_AttenuatorsSelection->GetSelection() );