# HG changeset patch # User Alain Mazy # Date 1616171866 -3600 # Node ID 4c71c5e2edce89bb4ba520888d3ccde90639e9ad # Parent d99afdf6d872acec302b07f2f6f956c214739085 fix memory handling in legacy read diff -r d99afdf6d872 -r 4c71c5e2edce Common/StoragePlugin.cpp --- a/Common/StoragePlugin.cpp Fri Mar 19 10:13:49 2021 +0100 +++ b/Common/StoragePlugin.cpp Fri Mar 19 17:37:46 2021 +0100 @@ -226,14 +226,13 @@ const char* uuid, OrthancPluginContentType type) { - OrthancPluginMemoryBuffer64* buffer = nullptr; - OrthancPluginErrorCode result = StorageReadWhole(buffer, uuid, type); // allocates the buffer but Orthanc won't delete it -> to delete ourselves + OrthancPluginMemoryBuffer64 buffer; + OrthancPluginErrorCode result = StorageReadWhole(&buffer, uuid, type); // will allocate OrthancPluginMemoryBuffer64 - if (buffer != nullptr) + if (result == OrthancPluginErrorCode_Success) { - *size = buffer->size; - memcpy(*content, buffer->data, buffer->size); - OrthancPluginFreeMemoryBuffer64(OrthancPlugins::GetGlobalContext(), buffer); + *size = buffer.size; + *content = buffer.data; // orthanc will free the buffer (we don't have to delete it ourselves) } return result;