diff Framework/Plugins/StorageBackend.cpp @ 252:33fa478c119a

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 13:33:48 +0200
parents 7f5ee2b42a86
children d663d9e44f8d
line wrap: on
line diff
--- a/Framework/Plugins/StorageBackend.cpp	Wed Apr 14 11:20:51 2021 +0200
+++ b/Framework/Plugins/StorageBackend.cpp	Wed Apr 14 13:33:48 2021 +0200
@@ -458,6 +458,20 @@
       {
       }
 
+      ~Visitor()
+      {
+        if (data_ != NULL /* this condition is invalidated by "Release()" */ &&
+            *data_ != NULL)
+        {
+          free(*data_);
+        }
+      }
+
+      void Release()
+      {
+        data_ = NULL;
+      }      
+
       virtual bool IsSuccess() const ORTHANC_OVERRIDE
       {
         return success_;
@@ -469,6 +483,11 @@
         {
           throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
         }
+        else if (data_ == NULL)
+        {
+          // "Release()" has been called
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+        }
         else
         {
           if (content.empty())
@@ -521,6 +540,8 @@
           accessor->ReadWhole(visitor, uuid, type);
         }
 
+        visitor.Release();
+
         return OrthancPluginErrorCode_Success;
       }
     }
@@ -609,7 +630,7 @@
     bool          success_;
       
   public:
-    StringVisitor(std::string& target) :
+    explicit StringVisitor(std::string& target) :
       target_(target),
       success_(false)
     {