Mercurial > hg > orthanc-object-storage
diff Common/StoragePlugin.cpp @ 43:4c71c5e2edce
fix memory handling in legacy read
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 19 Mar 2021 17:37:46 +0100 |
parents | 50d0be413c42 |
children | b922ae86bbe1 |
line wrap: on
line diff
--- 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;