tvg_saver: fix memory leaks
authorMira Grudzinska <m.grudzinska@samsung.com>
Sat, 6 Nov 2021 08:59:29 +0000 (09:59 +0100)
committerJunsuChoi <jsuya.choi@samsung.com>
Wed, 10 Nov 2021 01:43:08 +0000 (10:43 +0900)
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.

src/lib/tvgSaver.cpp
src/savers/tvg/tvgTvgSaver.cpp

index dc240d0..1a3e861 100644 (file)
@@ -99,12 +99,15 @@ Saver::~Saver()
 
 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();
     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 (saveModule->save(p, path, compress)) {
             pImpl->saveModule = saveModule;
index d7c9798..f1648fb 100644 (file)
@@ -748,9 +748,6 @@ bool TvgSaver::save(Paint* paint, const string& path, bool compress)
 {
     close();
 
-    this->path = strdup(path.c_str());
-    if (!this->path) return false;
-
     float x, y;
     x = y = 0;
     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;
     }
 
+    this->path = strdup(path.c_str());
+    if (!this->path) return false;
+
     this->paint = paint;
     this->compress = compress;