mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
lottie: fix potential memory leaks.
memory could be leaked during the slot property overriding.
This commit is contained in:
parent
d816d8fb5b
commit
d50eea2a2c
1 changed files with 48 additions and 14 deletions
|
@ -253,9 +253,10 @@ struct LottieGenericProperty : LottieProperty
|
||||||
{
|
{
|
||||||
//shallow copy, used for slot overriding
|
//shallow copy, used for slot overriding
|
||||||
delete(frames);
|
delete(frames);
|
||||||
if (other.frames) frames = other.frames;
|
if (other.frames) {
|
||||||
else value = other.value;
|
frames = other.frames;
|
||||||
const_cast<T&>(other).frames = nullptr;
|
const_cast<T&>(other).frames = nullptr;
|
||||||
|
} else value = other.value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,13 +364,24 @@ struct LottieColorStop : LottieProperty
|
||||||
|
|
||||||
~LottieColorStop()
|
~LottieColorStop()
|
||||||
{
|
{
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void release()
|
||||||
|
{
|
||||||
|
if (value.data) {
|
||||||
free(value.data);
|
free(value.data);
|
||||||
|
value.data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (!frames) return;
|
if (!frames) return;
|
||||||
|
|
||||||
for (auto p = frames->begin(); p < frames->end(); ++p) {
|
for (auto p = frames->begin(); p < frames->end(); ++p) {
|
||||||
free((*p).value.data);
|
free((*p).value.data);
|
||||||
}
|
}
|
||||||
free(frames->data);
|
free(frames->data);
|
||||||
free(frames);
|
free(frames);
|
||||||
|
frames = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LottieScalarFrame<ColorStop>& newFrame()
|
LottieScalarFrame<ColorStop>& newFrame()
|
||||||
|
@ -442,11 +454,15 @@ struct LottieColorStop : LottieProperty
|
||||||
LottieColorStop& operator=(const LottieColorStop& other)
|
LottieColorStop& operator=(const LottieColorStop& other)
|
||||||
{
|
{
|
||||||
//shallow copy, used for slot overriding
|
//shallow copy, used for slot overriding
|
||||||
delete(frames);
|
release();
|
||||||
if (other.frames) frames = other.frames;
|
if (other.frames) {
|
||||||
else value = other.value;
|
frames = other.frames;
|
||||||
count = other.count;
|
|
||||||
const_cast<LottieColorStop&>(other).frames = nullptr;
|
const_cast<LottieColorStop&>(other).frames = nullptr;
|
||||||
|
} else {
|
||||||
|
value = other.value;
|
||||||
|
const_cast<LottieColorStop&>(other).value.data = nullptr;
|
||||||
|
}
|
||||||
|
count = other.count;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,15 +539,28 @@ struct LottieTextDoc : LottieProperty
|
||||||
|
|
||||||
~LottieTextDoc()
|
~LottieTextDoc()
|
||||||
{
|
{
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void release()
|
||||||
|
{
|
||||||
|
if (value.text) {
|
||||||
free(value.text);
|
free(value.text);
|
||||||
|
value.text = nullptr;
|
||||||
|
}
|
||||||
|
if (value.name) {
|
||||||
free(value.name);
|
free(value.name);
|
||||||
|
value.name = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (!frames) return;
|
if (!frames) return;
|
||||||
|
|
||||||
for (auto p = frames->begin(); p < frames->end(); ++p) {
|
for (auto p = frames->begin(); p < frames->end(); ++p) {
|
||||||
free((*p).value.text);
|
free((*p).value.text);
|
||||||
free((*p).value.name);
|
free((*p).value.name);
|
||||||
}
|
}
|
||||||
delete(frames);
|
delete(frames);
|
||||||
|
frames = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LottieScalarFrame<TextDocument>& newFrame()
|
LottieScalarFrame<TextDocument>& newFrame()
|
||||||
|
@ -564,10 +593,15 @@ struct LottieTextDoc : LottieProperty
|
||||||
LottieTextDoc& operator=(const LottieTextDoc& other)
|
LottieTextDoc& operator=(const LottieTextDoc& other)
|
||||||
{
|
{
|
||||||
//shallow copy, used for slot overriding
|
//shallow copy, used for slot overriding
|
||||||
delete(frames);
|
release();
|
||||||
if (other.frames) frames = other.frames;
|
if (other.frames) {
|
||||||
else value = other.value;
|
frames = other.frames;
|
||||||
const_cast<LottieTextDoc&>(other).frames = nullptr;
|
const_cast<LottieTextDoc&>(other).frames = nullptr;
|
||||||
|
} else {
|
||||||
|
value = other.value;
|
||||||
|
const_cast<LottieTextDoc&>(other).value.text = nullptr;
|
||||||
|
const_cast<LottieTextDoc&>(other).value.name = nullptr;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue