diff --git a/src/mfast/coder/common/template_repo.h b/src/mfast/coder/common/template_repo.h index d949d56f..cc8c5102 100644 --- a/src/mfast/coder/common/template_repo.h +++ b/src/mfast/coder/common/template_repo.h @@ -14,10 +14,14 @@ class template_repo_base { template_repo_base(mfast::allocator *dictionary_alloc) : dictionary_alloc_(dictionary_alloc) {} virtual ~template_repo_base() { - for (auto &elem : vector_enties_) { + for (auto &elem : vector_entries_) { if (elem->of_array.capacity_in_bytes_) + { dictionary_alloc_->deallocate(elem->of_array.content_, elem->of_array.capacity_in_bytes_); + elem->of_array.capacity_in_bytes_ = 0; + elem->of_array.content_ = nullptr; + } } } @@ -33,9 +37,12 @@ class template_repo_base { void add_reset_entry(value_storage *entry) { reset_entries_.push_back(entry); } +#ifdef TESTING_TEMPLATE_REPO_BASE +public: +#endif void add_vector_entry(value_storage *entry) { if (dictionary_alloc_) - vector_enties_.push_back(entry); + vector_entries_.push_back(entry); } protected: @@ -43,7 +50,7 @@ class template_repo_base { typedef std::vector value_entries_t; value_entries_t reset_entries_; - value_entries_t vector_enties_; // for string and byteVector + value_entries_t vector_entries_; // for string and byteVector arena_allocator instruction_alloc_; mfast::allocator *dictionary_alloc_; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec793636..0a831d40 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -64,6 +64,7 @@ add_executable (mfast_test aggregate_view_test.cpp simple_coder_test.cpp scp_reset_test.cpp + template_repo_base.cpp message_pmap_test.cpp ) diff --git a/tests/template_repo_base.cpp b/tests/template_repo_base.cpp new file mode 100644 index 00000000..4dfcb464 --- /dev/null +++ b/tests/template_repo_base.cpp @@ -0,0 +1,41 @@ +#include "catch.hpp" + +#define TESTING_TEMPLATE_REPO_BASE +#include +#include +#include +#include +#include + +class template_repo_base_impl : public mfast::template_repo_base +{ +public: + template_repo_base_impl(mfast::allocator *dictionary_alloc) + : mfast::template_repo_base(dictionary_alloc) {} + + virtual mfast::template_instruction *get_template(uint32_t) + { + return nullptr; + } +}; + +TEST_CASE("Test template repo base with repeated pointers","[test_template_repo_base]") +{ + using namespace mfast; + + value_storage* storage_1_ = new value_storage(); + { + const char * test_data = "Test_Data"; + storage_1_->of_array.len_ = static_cast(std::strlen(test_data) + 1); + storage_1_->of_array.content_ = malloc_allocator::instance()->allocate(storage_1_->of_array.len_); + storage_1_->of_array.capacity_in_bytes_ = 9; + } + + { + template_repo_base_impl templ_repo(malloc_allocator::instance()); + templ_repo.add_vector_entry(storage_1_); + templ_repo.add_vector_entry(storage_1_); + } + + delete storage_1_; +}