mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
renderer/saver: enhanced safety
enhanced safety by taking into account the object reference counting.
This commit is contained in:
parent
a4ced1963e
commit
1228f52dc9
3 changed files with 10 additions and 6 deletions
|
@ -157,14 +157,17 @@ Result Saver::save(unique_ptr<Animation> animation, const string& path, uint32_t
|
|||
auto a = animation.release();
|
||||
if (!a) return Result::MemoryCorruption;
|
||||
|
||||
//animation holds the picture, it must be 1 at the bottom.
|
||||
auto remove = PP(a->picture())->refCnt <= 1 ? true : false;
|
||||
|
||||
if (mathZero(a->totalFrame())) {
|
||||
delete(a);
|
||||
if (remove) delete(a);
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
//Already on saving an other resource.
|
||||
if (pImpl->saveModule) {
|
||||
delete(a);
|
||||
if (remove) delete(a);
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
|
@ -173,12 +176,12 @@ Result Saver::save(unique_ptr<Animation> animation, const string& path, uint32_t
|
|||
pImpl->saveModule = saveModule;
|
||||
return Result::Success;
|
||||
} else {
|
||||
delete(a);
|
||||
if (remove) delete(a);
|
||||
delete(saveModule);
|
||||
return Result::Unknown;
|
||||
}
|
||||
}
|
||||
delete(a);
|
||||
if (remove) delete(a);
|
||||
return Result::NonSupport;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,8 @@ bool GifSaver::close()
|
|||
delete(bg);
|
||||
bg = nullptr;
|
||||
|
||||
delete(animation);
|
||||
//animation holds the picture, it must be 1 at the bottom.
|
||||
if (animation && PP(animation->picture())->refCnt <= 1) delete(animation);
|
||||
animation = nullptr;
|
||||
|
||||
free(path);
|
||||
|
|
|
@ -764,7 +764,7 @@ bool TvgSaver::close()
|
|||
{
|
||||
this->done();
|
||||
|
||||
delete(paint);
|
||||
if (paint && P(paint)->refCnt == 0) delete(paint);
|
||||
paint = nullptr;
|
||||
|
||||
free(path);
|
||||
|
|
Loading…
Add table
Reference in a new issue