Merge pull request #3622 from assimp/metadata_leak

Fixes a mem leak in aiMetadata::Set
pull/3623/head
Kim Kulling 2021-01-29 20:48:03 +01:00 committed by GitHub
commit 2e3d72abd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}