diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index 52121fbf1..e44b97bf3 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -350,6 +350,10 @@ struct aiMetadata { } else if (nullptr != mValues[index].mData && AI_AIMETADATA == mValues[index].mType) { *static_cast(mValues[index].mData) = value; } else { + if (nullptr != mValues[index].mData) { + delete mValues[index].mData; + mValues[index].mData = nullptr; + } mValues[index].mData = new T(value); } diff --git a/test/unit/utMetadata.cpp b/test/unit/utMetadata.cpp index 81ab61435..d4b0b158f 100644 --- a/test/unit/utMetadata.cpp +++ b/test/unit/utMetadata.cpp @@ -51,11 +51,11 @@ class utMetadata: public ::testing::Test { protected: aiMetadata *m_data; - virtual void SetUp() { + void SetUp() override { m_data = nullptr; } - virtual void TearDown() { + void TearDown() override { aiMetadata::Dealloc( m_data ); } @@ -261,3 +261,12 @@ TEST_F( utMetadata, copy_test ) { EXPECT_EQ( metaVal, v ); } } + +TEST_F( utMetadata, set_test ) { + aiMetadata v; + const std::string key_bool = "test_bool"; + v.Set(1, key_bool, true); + v.Set(1, key_bool, true); + v.Set(1, key_bool, true); + v.Set(1, key_bool, true); +}