diff Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 284:64bf8914f02e

sync + no more need of "-DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES" to dynamically link against system-wide orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 12 Jun 2021 08:49:52 +0200
parents c7dc70a0a477
children 1280b40d6696
line wrap: on
line diff
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp	Fri Apr 23 10:02:00 2021 +0200
+++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp	Sat Jun 12 08:49:52 2021 +0200
@@ -2726,10 +2726,18 @@
           delete *it;
         }
 
+        size_ = 0;
         content_.clear();
       }
 
-      void Flatten(std::string& target) const
+      /**
+       * Since Orthanc 1.9.3, this function also clears the content of
+       * the ChunkedBuffer in order to mimic the behavior of the
+       * original class "Orthanc::ChunkedBuffer". This prevents the
+       * forgetting of calling "Clear()" in order to reduce memory
+       * consumption.
+       **/
+      void Flatten(std::string& target)
       {
         target.resize(size_);
 
@@ -2745,10 +2753,14 @@
             memcpy(&target[pos], (*it)->c_str(), s);
             pos += s;
           }
+
+          delete *it;
         }
 
-        assert(size_ == 0 ||
-               pos == target.size());
+        assert(pos == target.size());
+
+        size_ = 0;
+        content_.clear();
       }
 
       void AddChunk(const void* data,
@@ -2779,7 +2791,7 @@
         return headers_;
       }
 
-      const ChunkedBuffer& GetBody() const
+      ChunkedBuffer& GetBody()
       {
         return body_;
       }