mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +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();
|
auto a = animation.release();
|
||||||
if (!a) return Result::MemoryCorruption;
|
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())) {
|
if (mathZero(a->totalFrame())) {
|
||||||
delete(a);
|
if (remove) delete(a);
|
||||||
return Result::InsufficientCondition;
|
return Result::InsufficientCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Already on saving an other resource.
|
//Already on saving an other resource.
|
||||||
if (pImpl->saveModule) {
|
if (pImpl->saveModule) {
|
||||||
delete(a);
|
if (remove) delete(a);
|
||||||
return Result::InsufficientCondition;
|
return Result::InsufficientCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,12 +176,12 @@ Result Saver::save(unique_ptr<Animation> animation, const string& path, uint32_t
|
||||||
pImpl->saveModule = saveModule;
|
pImpl->saveModule = saveModule;
|
||||||
return Result::Success;
|
return Result::Success;
|
||||||
} else {
|
} else {
|
||||||
delete(a);
|
if (remove) delete(a);
|
||||||
delete(saveModule);
|
delete(saveModule);
|
||||||
return Result::Unknown;
|
return Result::Unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(a);
|
if (remove) delete(a);
|
||||||
return Result::NonSupport;
|
return Result::NonSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,8 @@ bool GifSaver::close()
|
||||||
delete(bg);
|
delete(bg);
|
||||||
bg = nullptr;
|
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;
|
animation = nullptr;
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
|
|
|
@ -764,7 +764,7 @@ bool TvgSaver::close()
|
||||||
{
|
{
|
||||||
this->done();
|
this->done();
|
||||||
|
|
||||||
delete(paint);
|
if (paint && P(paint)->refCnt == 0) delete(paint);
|
||||||
paint = nullptr;
|
paint = nullptr;
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
|
|
Loading…
Add table
Reference in a new issue