lottie: Prevent memory leak when file is invalid

When json file is invalid in the parser,
the LottieComposition object is not released and the parse() returns false.
To prevent memory leaks, free the memory before returning false.

related issue : https://github.com/thorvg/thorvg/issues/2070
This commit is contained in:
JunsuChoi 2024-03-19 10:17:45 +09:00 committed by Hermet Park
parent 6120729554
commit dd2e7b9b4e
2 changed files with 7 additions and 4 deletions

View file

@ -207,7 +207,7 @@ float LottieLayer::remap(float frameNo)
LottieComposition::~LottieComposition()
{
if (!initiated) delete(root->scene);
if (!initiated && root) delete(root->scene);
delete(root);
free(version);

View file

@ -1316,7 +1316,10 @@ bool LottieParser::parse()
else skip(key);
}
if (Invalid() || !comp->root) return false;
if (Invalid() || !comp->root) {
delete(comp);
return false;
}
comp->root->inFrame = comp->startFrame;
comp->root->outFrame = comp->endFrame;