Revert "Fixed memory leaks"

This reverts commit a9efbf4716.

The commit broke compiles with scripting
This commit is contained in:
Seth Hillbrand 2018-12-11 10:12:44 -08:00
parent 2c53ab3d8c
commit e307d9318b
11 changed files with 30 additions and 22 deletions

View File

@ -79,7 +79,7 @@ private:
wxString m_ConvertedFileName; wxString m_ConvertedFileName;
wxSize m_frameSize; wxSize m_frameSize;
wxPoint m_framePos; wxPoint m_framePos;
std::unique_ptr<wxConfigBase> m_config; wxConfigBase* m_config;
public: public:
BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ); BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
@ -223,6 +223,8 @@ 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
*/ */

View File

@ -29,6 +29,7 @@
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 )
{ {
} }
@ -47,7 +48,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.get() ); m_history->Load( *m_config );
// 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.
@ -63,11 +64,14 @@ void BIN_MOD::End()
{ {
if( m_config ) if( m_config )
{ {
m_history->Save( *m_config.get() ); m_history->Save( *m_config );
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.
m_config.reset(); // Might be NULL if called twice, in which case nothing happens.
delete m_config;
m_config = 0;
} }
} }

View File

@ -248,13 +248,15 @@ double RoundTo0( double x, double precision )
} }
std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName ) wxConfigBase* GetNewConfig( const wxString& aProgName )
{ {
wxConfigBase* cfg = 0;
wxFileName configname; wxFileName configname;
configname.AssignDir( GetKicadConfigPath() ); configname.AssignDir( GetKicadConfigPath() );
configname.SetFullName( aProgName ); configname.SetFullName( aProgName );
return std::make_unique<wxConfig>( wxT( "" ), wxT( "" ), configname.GetFullPath() ); cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
return cfg;
} }

View File

@ -154,6 +154,7 @@ 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;
@ -172,7 +173,9 @@ 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;
@ -559,7 +562,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.
auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) ); wxConfigBase* 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 ) )

View File

@ -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 );
auto eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() ); wxConfigBase* eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() );
m_galDisplayOptions.ReadConfig( eeschemaConfig.get(), eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY ); m_galDisplayOptions.ReadConfig( eeschemaConfig, eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY );
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType; EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType;

View File

@ -33,7 +33,6 @@
#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;
@ -56,7 +55,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.
std::unique_ptr<wxConfigBase> m_config; ///< maybe from $HOME/.${m_name} wxConfigBase* m_config; ///< maybe from $HOME/.${m_name}
FILE_HISTORY* m_history; FILE_HISTORY* m_history;
wxString m_help_file; wxString m_help_file;

View File

@ -43,7 +43,6 @@
#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"
@ -311,7 +310,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.
*/ */
std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName ); 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.

View File

@ -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.get(); } wxConfigBase* KifaceSettings() const { return m_bm.m_config; }
/** /**
* Function StartFlags * Function StartFlags

View File

@ -32,7 +32,6 @@
#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>
@ -185,7 +184,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.get(); } VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
VTBL_ENTRY void SetEditorName( const wxString& aFileName ); VTBL_ENTRY void SetEditorName( const wxString& aFileName );
@ -363,7 +362,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
std::unique_ptr<wxConfigBase> m_common_settings; wxConfigBase* m_common_settings;
/// full path to this program /// full path to this program
wxString m_bin_dir; wxString m_bin_dir;

View File

@ -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.get(); } wxConfigBase* PgmSettings() { return m_bm.m_config; }
SEARCH_STACK& SysSearch() { return m_bm.m_search; } 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_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
m_currAttenuator = m_attenuator_list[0]; m_currAttenuator = m_attenuator_list[0];
auto config = GetNewConfig( Pgm().App().GetAppName() ); wxConfigBase* config = GetNewConfig( Pgm().App().GetAppName() );
LoadSettings( config.get() ); LoadSettings( config );
ReadDataFile(); ReadDataFile();
TranslineTypeSelection( m_currTransLineType ); TranslineTypeSelection( m_currTransLineType );
m_TranslineSelection->SetSelection( m_currTransLineType ); m_TranslineSelection->SetSelection( m_currTransLineType );
TW_Init( config.get() ); TW_Init( config );
SetAttenuator( m_AttenuatorsSelection->GetSelection() ); SetAttenuator( m_AttenuatorsSelection->GetSelection() );