diff --git a/source/adios2/engine/bp5/BP5Writer.cpp b/source/adios2/engine/bp5/BP5Writer.cpp index 7c5af59723..6c8e9293e6 100644 --- a/source/adios2/engine/bp5/BP5Writer.cpp +++ b/source/adios2/engine/bp5/BP5Writer.cpp @@ -547,12 +547,14 @@ void BP5Writer::EndStep() m_Profiler.Start("AWD"); // TSInfo destructor would delete the DataBuffer so we need to save it // for async IO and let the writer free it up when not needed anymore - adios2::format::BufferV *databuf = TSInfo.DataBuffer; - TSInfo.DataBuffer = NULL; m_AsyncWriteLock.lock(); m_flagRush = false; m_AsyncWriteLock.unlock(); - WriteData(databuf); + + // WriteData will free TSInfo.DataBuffer + WriteData(TSInfo.DataBuffer); + TSInfo.DataBuffer = NULL; + m_Profiler.Stop("AWD"); /* diff --git a/source/adios2/toolkit/format/bp5/BP5Serializer.cpp b/source/adios2/toolkit/format/bp5/BP5Serializer.cpp index 06d2176856..af4c780cf3 100644 --- a/source/adios2/toolkit/format/bp5/BP5Serializer.cpp +++ b/source/adios2/toolkit/format/bp5/BP5Serializer.cpp @@ -1333,19 +1333,27 @@ BP5Serializer::TimestepInfo BP5Serializer::CloseTimestep(int timestep, MBase->BitField = tmp; NewAttribute = false; - struct TimestepInfo Ret - { - Formats, Metadata, AttrData, CurDataBuffer - }; + struct TimestepInfo Ret; + Ret.NewMetaMetaBlocks = Formats; + Ret.MetaEncodeBuffer.reset(Metadata); + Ret.AttributeEncodeBuffer.reset(AttrData); + Ret.DataBuffer = CurDataBuffer; CurDataBuffer = NULL; + if (Info.AttributeFields) + { free_FMfield_list(Info.AttributeFields); - Info.AttributeFields = NULL; + Info.AttributeFields = NULL; + } Info.AttributeFieldCount = 0; + if (Info.AttributeData) + { free(Info.AttributeData); - Info.AttributeData = NULL; + Info.AttributeData = NULL; + } Info.AttributeSize = 0; + return Ret; } diff --git a/source/adios2/toolkit/format/bp5/BP5Serializer.h b/source/adios2/toolkit/format/bp5/BP5Serializer.h index 5ceeb54dad..b0f225b0df 100644 --- a/source/adios2/toolkit/format/bp5/BP5Serializer.h +++ b/source/adios2/toolkit/format/bp5/BP5Serializer.h @@ -36,17 +36,9 @@ class BP5Serializer : virtual public BP5Base struct TimestepInfo { std::vector NewMetaMetaBlocks; - Buffer *MetaEncodeBuffer; - Buffer *AttributeEncodeBuffer; - BufferV *DataBuffer; - - ~TimestepInfo() - { - delete MetaEncodeBuffer; - if (AttributeEncodeBuffer) - delete AttributeEncodeBuffer; - delete DataBuffer; - } + std::shared_ptr MetaEncodeBuffer; + std::shared_ptr AttributeEncodeBuffer; + BufferV* DataBuffer; }; typedef struct _MetadataInfo