diff options
author | Cisco Cervellera <cisco.cervellera@arm.com> | 2021-09-15 09:35:24 +0100 |
---|---|---|
committer | Cisco Cervellera <cisco.cervellera@arm.com> | 2021-09-15 09:35:24 +0100 |
commit | d996cc524afba7018c260329100c6e5ce458a7fe (patch) | |
tree | 3945c2d268b64ec45e0aaa2164d6778af455b115 /source/application/main | |
parent | f6753c96891fee429fe9eba26940e5cee0203d4d (diff) | |
download | ml-embedded-evaluation-kit-d996cc524afba7018c260329100c6e5ce458a7fe.tar.gz |
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
Diffstat (limited to 'source/application/main')
-rw-r--r-- | source/application/main/include/AppContext.hpp | 6 |
1 files changed, 6 insertions, 0 deletions
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<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); } |