From 324510173aa97015d58010bc9f69824e6b1f2cc6 Mon Sep 17 00:00:00 2001 From: W0LF Date: Mon, 3 Jul 2023 15:58:51 +0300 Subject: [PATCH] Fixed memory leak. --- bulls-and-cows-cpp/CGame.cpp | 7 ++++++- bulls-and-cows-cpp/CGame.h | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bulls-and-cows-cpp/CGame.cpp b/bulls-and-cows-cpp/CGame.cpp index 6a0a7e9..9217bdb 100644 --- a/bulls-and-cows-cpp/CGame.cpp +++ b/bulls-and-cows-cpp/CGame.cpp @@ -46,7 +46,7 @@ void CGame::Start() do { PrintGameHeader(); - ShowGuessedNumber(false); + ShowGuessedNumber(true); PrintSteps(); ret = GetNumber(step); switch (ret) @@ -169,3 +169,8 @@ int CGame::GetNumber(CStep step) return 0; } + +CGame::~CGame() +{ + delete[] m_uGuessedNumber; +} diff --git a/bulls-and-cows-cpp/CGame.h b/bulls-and-cows-cpp/CGame.h index a171d27..9e0f7c1 100644 --- a/bulls-and-cows-cpp/CGame.h +++ b/bulls-and-cows-cpp/CGame.h @@ -36,18 +36,18 @@ public: void Init(int); void Start(); + + ~CGame(); }; template bool CGame::IsEqual(const T number, const N digit, int i) { - i--; bool result = false; - while (i >= 0) + while ((--i) >= 0) { if (digit == number[i]) result = true; - i--; } return result; }