diff --git a/common/git/kicad_git_errors.h b/common/git/kicad_git_errors.h index 2846dbfb1b..91d7dbc4b1 100644 --- a/common/git/kicad_git_errors.h +++ b/common/git/kicad_git_errors.h @@ -33,6 +33,7 @@ class KIGIT_ERRORS public: KIGIT_ERRORS() = default; + virtual ~KIGIT_ERRORS() = default; const std::vector& GetErrorStrings() const { diff --git a/kicad/project_tree.cpp b/kicad/project_tree.cpp index a15dc35c7f..10cba5f4bb 100644 --- a/kicad/project_tree.cpp +++ b/kicad/project_tree.cpp @@ -50,7 +50,7 @@ PROJECT_TREE::PROJECT_TREE( PROJECT_TREE_PANE* parent ) : m_statusImageList( nullptr ) { m_projectTreePane = parent; - m_gitCommon = new KIGIT_COMMON( nullptr ); + m_gitCommon = std::make_unique( nullptr ); // Make sure the GUI font scales properly on GTK SetFont( KIUI::GetControlFont( this ) ); diff --git a/kicad/project_tree.h b/kicad/project_tree.h index 80c5a98303..bd7e63ba58 100644 --- a/kicad/project_tree.h +++ b/kicad/project_tree.h @@ -25,6 +25,8 @@ #ifndef PROJECT_TREE_H #define PROJECT_TREE_H +#include + #include #include @@ -42,10 +44,10 @@ class PROJECT_TREE : public wxTreeCtrl DECLARE_DYNAMIC_CLASS( PROJECT_TREE ) private: - PROJECT_TREE_PANE* m_projectTreePane; - wxImageList* m_imageList; - wxImageList* m_statusImageList; - KIGIT_COMMON* m_gitCommon; + PROJECT_TREE_PANE* m_projectTreePane; + wxImageList* m_imageList; + wxImageList* m_statusImageList; + std::unique_ptr m_gitCommon; public: PROJECT_TREE_PANE* GetProjectTreePane() const { return m_projectTreePane; } @@ -58,7 +60,7 @@ public: void SetGitRepo( git_repository* aRepo ) { m_gitCommon->SetRepo( aRepo ); } git_repository* GetGitRepo() const { return m_gitCommon->GetRepo(); } - KIGIT_COMMON* GitCommon() const { return m_gitCommon; } + KIGIT_COMMON* GitCommon() const { return m_gitCommon.get(); } private: /* overridden sort function */ diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index 6ac4b04034..5a890d4225 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -1482,6 +1482,13 @@ void PROJECT_TREE_PANE::EmptyTreePrj() shutdownFileWatcher(); m_TreeProject->DeleteAllItems(); + + // Remove the git repository when the project is unloaded + if( m_TreeProject->GetGitRepo() ) + { + git_repository_free( m_TreeProject->GetGitRepo() ); + m_TreeProject->SetGitRepo( nullptr ); + } }