Fixes a mem leak in aiMetadata::Set

pull/3622/head
Kim Kulling 2021-01-29 20:25:02 +01:00
parent 3174a9cac8
commit 79a442f95d
2 changed files with 15 additions and 2 deletions

View File

@ -350,6 +350,10 @@ struct aiMetadata {
} else if (nullptr != mValues[index].mData && AI_AIMETADATA == mValues[index].mType) {
*static_cast<T *>(mValues[index].mData) = value;
} else {
if (nullptr != mValues[index].mData) {
delete mValues[index].mData;
mValues[index].mData = nullptr;
}
mValues[index].mData = new T(value);
}

View File

@ -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);
}