From f5a71ca80798c1dc0b62f4da47d3818d087ea55e Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 14 Dec 2019 13:42:34 +0100 Subject: [PATCH] Fixed memory leak in growth rate library. --- src/Library/GrowthRates/GrowthRate.hpp | 2 ++ src/Library/GrowthRates/GrowthRateLibrary.hpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/Library/GrowthRates/GrowthRate.hpp b/src/Library/GrowthRates/GrowthRate.hpp index 1c9f210..b05a4c4 100644 --- a/src/Library/GrowthRates/GrowthRate.hpp +++ b/src/Library/GrowthRates/GrowthRate.hpp @@ -6,6 +6,8 @@ namespace CreatureLib::Library { class GrowthRate { public: + virtual ~GrowthRate() = default; + [[nodiscard]] virtual uint8_t CalculateLevel(uint32_t experience) const = 0; [[nodiscard]] virtual uint32_t CalculateExperience(uint8_t level) const = 0; }; diff --git a/src/Library/GrowthRates/GrowthRateLibrary.hpp b/src/Library/GrowthRates/GrowthRateLibrary.hpp index 3430ba8..2a7a008 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.hpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.hpp @@ -12,6 +12,12 @@ namespace CreatureLib::Library { std::unordered_map _growthRates; public: + ~GrowthRateLibrary(){ + for (auto gr: _growthRates){ + delete gr.second; + } + } + [[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const; [[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const;