saver: ++robustness

do not delete the given picture if the reference counting is
more than 0.
This commit is contained in:
Hermet Park 2024-03-02 06:26:51 +09:00
parent 0c602291cb
commit a741778dab

View file

@ -22,6 +22,7 @@
#include "tvgCommon.h"
#include "tvgSaveModule.h"
#include "tvgPaint.h"
#ifdef THORVG_TVG_SAVER_SUPPORT
#include "tvgTvgSaver.h"
@ -123,7 +124,7 @@ Result Saver::save(unique_ptr<Paint> paint, const string& path, uint32_t quality
//Already on saving an other resource.
if (pImpl->saveModule) {
delete(p);
if (P(p)->refCnt == 0) delete(p);
return Result::InsufficientCondition;
}
@ -132,12 +133,12 @@ Result Saver::save(unique_ptr<Paint> paint, const string& path, uint32_t quality
pImpl->saveModule = saveModule;
return Result::Success;
} else {
delete(p);
if (P(p)->refCnt == 0) delete(p);
delete(saveModule);
return Result::Unknown;
}
}
delete(p);
if (P(p)->refCnt == 0) delete(p);
return Result::NonSupport;
}