From d996cc524afba7018c260329100c6e5ce458a7fe Mon Sep 17 00:00:00 2001 From: Cisco Cervellera Date: Wed, 15 Sep 2021 09:35:24 +0100 Subject: MLECO-2135: Memory leak bug The ApplicationContext::Set function allocates always new memory for the attibute. When called multiple times (like it is done in most of the UseCaseHandler) this will generate a memory leak. The function now checks if the attibute exists; If it does it frees the memory and then allocate memory for the new attribute. Change-Id: I21db10009d6d0e360eab2dd33c344ef72eafe77f --- source/application/main/include/AppContext.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/application/main/include/AppContext.hpp b/source/application/main/include/AppContext.hpp index 10de126..13f2686 100644 --- a/source/application/main/include/AppContext.hpp +++ b/source/application/main/include/AppContext.hpp @@ -58,6 +58,12 @@ namespace app { template void Set(const std::string &name, T object) { + /* check if we have already the attribute allocated. */ + if( true == this->Has(name) ){ + //delete its value + delete this->m_attributes[name]; + } + /* allocate new value */ this->m_attributes[name] = new Attribute(object); } -- cgit v1.2.1