From 3d43ea07d565dcfb08bf8866770f3d81c8cfc181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Cavelan?= Date: Thu, 16 Jan 2025 15:29:58 +0100 Subject: [PATCH] fix memory leak from missing destructor in Sampler --- model/Transmission/PerHost.h | 15 +++++++++------ model/Transmission/transmission.h | 2 -- model/util/sampler.h | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/model/Transmission/PerHost.h b/model/Transmission/PerHost.h index 2753e910..4bf60cd0 100644 --- a/model/Transmission/PerHost.h +++ b/model/Transmission/PerHost.h @@ -45,11 +45,16 @@ class HumanVectorInterventionComponent; * Parameters are read from XML, and the availability rate is adjusted. */ class PerHostAnophParams { public: - static inline void initReserve (size_t numSpecies) { - params.reserve (numSpecies); - } + PerHostAnophParams (const scnXml::Mosq& mosq); + + PerHostAnophParams(PerHostAnophParams&&) noexcept = default; + PerHostAnophParams& operator=(PerHostAnophParams&&) noexcept = default; + + PerHostAnophParams(const PerHostAnophParams&) = delete; + PerHostAnophParams& operator=(const PerHostAnophParams&) = delete; + static inline void init (const scnXml::Mosq& mosq) { - params.push_back(PerHostAnophParams{ mosq }); + params.emplace_back(mosq); } /// Get the number of vector species @@ -133,8 +138,6 @@ class PerHostAnophParams { //@} private: - PerHostAnophParams (const scnXml::Mosq& mosq); - static vector params; static vector entoAvailabilityPercentiles; diff --git a/model/Transmission/transmission.h b/model/Transmission/transmission.h index 8b4b90d4..959c3b17 100644 --- a/model/Transmission/transmission.h +++ b/model/Transmission/transmission.h @@ -334,8 +334,6 @@ inline VectorModel *createVectorModel(const scnXml::Entomology &entoData, int po // Sort Anopheles by Decreasing EIR sort(anophelesList.begin(), anophelesList.end(), anophelesCompare); - PerHostAnophParams::initReserve(numSpecies); - for (size_t i = 0; i < numSpecies; ++i) { auto anoph = anophelesList[i]; diff --git a/model/util/sampler.h b/model/util/sampler.h index 9a4597c7..f30f5633 100644 --- a/model/util/sampler.h +++ b/model/util/sampler.h @@ -32,6 +32,7 @@ namespace OM { namespace util { class Sampler { public: + virtual ~Sampler() = default; virtual double sample(LocalRng& rng) const = 0; virtual void scaleMean( double scalar ) = 0; virtual double mean() const = 0;