Fixes a mem leak in aiMetadata::Set
parent
3174a9cac8
commit
79a442f95d
|
@ -350,6 +350,10 @@ struct aiMetadata {
|
||||||
} else if (nullptr != mValues[index].mData && AI_AIMETADATA == mValues[index].mType) {
|
} else if (nullptr != mValues[index].mData && AI_AIMETADATA == mValues[index].mType) {
|
||||||
*static_cast<T *>(mValues[index].mData) = value;
|
*static_cast<T *>(mValues[index].mData) = value;
|
||||||
} else {
|
} else {
|
||||||
|
if (nullptr != mValues[index].mData) {
|
||||||
|
delete mValues[index].mData;
|
||||||
|
mValues[index].mData = nullptr;
|
||||||
|
}
|
||||||
mValues[index].mData = new T(value);
|
mValues[index].mData = new T(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,11 @@ class utMetadata: public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
aiMetadata *m_data;
|
aiMetadata *m_data;
|
||||||
|
|
||||||
virtual void SetUp() {
|
void SetUp() override {
|
||||||
m_data = nullptr;
|
m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void TearDown() {
|
void TearDown() override {
|
||||||
aiMetadata::Dealloc( m_data );
|
aiMetadata::Dealloc( m_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,3 +261,12 @@ TEST_F( utMetadata, copy_test ) {
|
||||||
EXPECT_EQ( metaVal, v );
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue