changeset 6027:83deef099c75 attach-custom-data

fix memory leak
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 24 Feb 2025 17:54:27 +0100
parents 4db83cdab1bc
children e282d55e043c
files OrthancServer/Plugins/Engine/OrthancPlugins.cpp
diffstat 1 files changed, 6 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Feb 24 17:19:33 2025 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Feb 24 17:54:27 2025 +0100
@@ -1012,18 +1012,18 @@
                           CompressionType compression,
                           const DicomInstanceToStore* dicomInstance /* can be NULL if not a DICOM instance */) ORTHANC_OVERRIDE
       {
-        OrthancPluginMemoryBuffer customDataBuffer;
+        MemoryBufferRaii customDataBuffer;
         OrthancPluginErrorCode error;
 
         if (dicomInstance != NULL)
         {
           Orthanc::OrthancPlugins::DicomInstanceFromCallback wrapped(*dicomInstance);
-          error = create_(&customDataBuffer, uuid.c_str(), content, size, Plugins::Convert(type), Plugins::Convert(compression),
+          error = create_(customDataBuffer.GetObject(), uuid.c_str(), content, size, Plugins::Convert(type), Plugins::Convert(compression),
                           reinterpret_cast<OrthancPluginDicomInstance*>(&wrapped));
         }
         else
         {
-          error = create_(&customDataBuffer, uuid.c_str(), content, size, Plugins::Convert(type), Plugins::Convert(compression), NULL);
+          error = create_(customDataBuffer.GetObject(), uuid.c_str(), content, size, Plugins::Convert(type), Plugins::Convert(compression), NULL);
         }
 
         if (error != OrthancPluginErrorCode_Success)
@@ -1031,11 +1031,9 @@
           errorDictionary_.LogError(error, true);
           throw OrthancException(static_cast<ErrorCode>(error));
         }
-
-        if (customDataBuffer.size > 0)
-        {
-          customData.assign(reinterpret_cast<char*>(customDataBuffer.data),
-                            static_cast<size_t>(customDataBuffer.size));
+        else
+        {
+          customDataBuffer.ToString(customData);
         }
       }