From a8c59c41bc103f0336d9982369be5dd85ac68111 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 28 Feb 2022 18:51:47 +0100 Subject: Fix majors memory leaks (TODO: shared_ptr for Game objects and implement ~Game()) --- src/game_tab/left_panel/board/BoardCanvas.cpp | 5 +++++ src/game_tab/left_panel/board/BoardCanvas.hpp | 1 + src/game_tab/right_panel/LiveEngineDialog.cpp | 10 ++++++++-- src/game_tab/right_panel/LiveEngineDialog.hpp | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/game_tab') diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 237a68a..4b5f3fb 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -14,6 +14,11 @@ BoardCanvas::BoardCanvas(wxFrame *parent) ApplyPreferences(); } +BoardCanvas::~BoardCanvas() { + delete t; + delete t_captures; +} + BoardCanvas::BoardCanvas(wxFrame *parent, std::uint32_t square_width, bool frozen) : BoardCanvas(parent) { diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 34c4911..83c960a 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -54,6 +54,7 @@ class BoardCanvas : public wxPanel { public: BoardCanvas(wxFrame *parent); BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen); + ~BoardCanvas(); void ApplyPreferences(); void DrawBoard(wxPaintDC &dc); void OnPaint(wxPaintEvent &event); diff --git a/src/game_tab/right_panel/LiveEngineDialog.cpp b/src/game_tab/right_panel/LiveEngineDialog.cpp index 1f509ae..73d3eb3 100644 --- a/src/game_tab/right_panel/LiveEngineDialog.cpp +++ b/src/game_tab/right_panel/LiveEngineDialog.cpp @@ -13,6 +13,13 @@ LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name) Bind(wxEVT_CLOSE_WINDOW, &LiveEngineDialog::OnClose, this); } +LiveEngineDialog::~LiveEngineDialog() { + if (engine != NULL) { + wxLogDebug("LiveEngineDialog destructor: delete engine"); + delete engine; + } +} + void LiveEngineDialog::InitEngine() { if (engine == NULL) { wxLogDebug("Start engine: %s", engine_name); @@ -51,9 +58,8 @@ void LiveEngineDialog::OnClose(wxCloseEvent &e) { timer.Stop(); engine->stop(); engine->quit(); - delete engine; } - e.Skip(); + Destroy(); } void LiveEngineDialog::SetFEN(std::string fen) { diff --git a/src/game_tab/right_panel/LiveEngineDialog.hpp b/src/game_tab/right_panel/LiveEngineDialog.hpp index 999002f..0996ba0 100644 --- a/src/game_tab/right_panel/LiveEngineDialog.hpp +++ b/src/game_tab/right_panel/LiveEngineDialog.hpp @@ -10,6 +10,7 @@ class LiveEngineDialog : public DialogLiveEngine { public: LiveEngineDialog(wxWindow *parent, std::string engine_name); + ~LiveEngineDialog(); void InitEngine(); void TogglePauseEngine(wxCommandEvent &event); void OnTimerTick(wxTimerEvent &event); -- cgit v1.2.3