mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
tvg_saver: fix memory leaks
In the cae when Result::InsufficientCondition was retured by the save() api, the user had to remember to delete the passed paint - fixed. Also path was not released.
This commit is contained in:
parent
6ba2bc8eb3
commit
14c1562b36
2 changed files with 9 additions and 6 deletions
|
@ -99,12 +99,15 @@ Saver::~Saver()
|
||||||
|
|
||||||
Result Saver::save(std::unique_ptr<Paint> paint, const string& path, bool compress) noexcept
|
Result Saver::save(std::unique_ptr<Paint> paint, const string& path, bool compress) noexcept
|
||||||
{
|
{
|
||||||
//Already on saving an other resource.
|
|
||||||
if (pImpl->saveModule) return Result::InsufficientCondition;
|
|
||||||
|
|
||||||
auto p = paint.release();
|
auto p = paint.release();
|
||||||
if (!p) return Result::MemoryCorruption;
|
if (!p) return Result::MemoryCorruption;
|
||||||
|
|
||||||
|
//Already on saving an other resource.
|
||||||
|
if (pImpl->saveModule) {
|
||||||
|
delete(p);
|
||||||
|
return Result::InsufficientCondition;
|
||||||
|
}
|
||||||
|
|
||||||
if (auto saveModule = _find(path)) {
|
if (auto saveModule = _find(path)) {
|
||||||
if (saveModule->save(p, path, compress)) {
|
if (saveModule->save(p, path, compress)) {
|
||||||
pImpl->saveModule = saveModule;
|
pImpl->saveModule = saveModule;
|
||||||
|
|
|
@ -748,9 +748,6 @@ bool TvgSaver::save(Paint* paint, const string& path, bool compress)
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
||||||
this->path = strdup(path.c_str());
|
|
||||||
if (!this->path) return false;
|
|
||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
paint->bounds(&x, &y, &vsize[0], &vsize[1], false);
|
paint->bounds(&x, &y, &vsize[0], &vsize[1], false);
|
||||||
|
@ -764,6 +761,9 @@ bool TvgSaver::save(Paint* paint, const string& path, bool compress)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->path = strdup(path.c_str());
|
||||||
|
if (!this->path) return false;
|
||||||
|
|
||||||
this->paint = paint;
|
this->paint = paint;
|
||||||
this->compress = compress;
|
this->compress = compress;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue