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
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 @@
template<typename T>
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<T>(object);
}