renderer/saver: enhanced safety

enhanced safety by taking into account the object reference counting.
This commit is contained in:
Hermet Park 2024-04-03 20:00:56 +09:00 committed by Hermet Park
parent a4ced1963e
commit 1228f52dc9
3 changed files with 10 additions and 6 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -764,7 +764,7 @@ bool TvgSaver::close()
{
this->done();
delete(paint);
if (paint && P(paint)->refCnt == 0) delete(paint);
paint = nullptr;
free(path);