Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for ASAN issue related to JoinedDimArray handling in BP5 deserializer #3963

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions source/adios2/toolkit/format/bp5/BP5Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,14 +761,7 @@ void BP5Deserializer::InstallMetaData(void *MetadataBlock, size_t BlockLen, size
m_FreeableMBA = nullptr;
}

JoinedDimArray.resize(Step + 1);
if (JoinedDimArray[Step] == nullptr)
{
m_JoinedDimenOffsetArrays = new std::vector<void *>();
m_JoinedDimenOffsetArrays->resize(writerCohortSize);
JoinedDimArray[Step] = m_JoinedDimenOffsetArrays;
m_FreeableJDOA = nullptr;
}
JDAIdx = Step;
}
else
{
Expand All @@ -782,16 +775,11 @@ void BP5Deserializer::InstallMetaData(void *MetadataBlock, size_t BlockLen, size
m_MetadataBaseAddrs->resize(writerCohortSize);
}

if (!m_JoinedDimenOffsetArrays)
{
m_JoinedDimenOffsetArrays = new std::vector<void *>();
m_FreeableJDOA = m_JoinedDimenOffsetArrays;
}
if (writerCohortSize > m_JoinedDimenOffsetArrays->size())
{
m_JoinedDimenOffsetArrays->resize(writerCohortSize);
}
JDAIdx = 0;
}
JoinedDimArray.resize(JDAIdx + 1);
JoinedDimArray[JDAIdx].resize(writerCohortSize);

(*m_MetadataBaseAddrs)[WriterRank] = BaseData;

size_t JoinedDimenTotal = 0;
Expand Down Expand Up @@ -823,13 +811,15 @@ void BP5Deserializer::InstallMetaData(void *MetadataBlock, size_t BlockLen, size

// Allocate memory to hold new offset values for Joined Arrays
size_t CurJoinedDimenOffset = 0;
size_t *JoinedDimenOffsetArray = NULL;
if (JoinedDimenTotal)
JoinedDimenOffsetArray =
(size_t *)malloc(JoinedDimenTotal * writerCohortSize * sizeof(size_t));
{
JoinedDimArray[JDAIdx][WriterRank] =
(size_t *)realloc(JoinedDimArray[JDAIdx][WriterRank],
JoinedDimenTotal * writerCohortSize * sizeof(size_t));
}

// store this away so it can be deallocated later
(*m_JoinedDimenOffsetArrays)[WriterRank] = JoinedDimenOffsetArray;
// shortcut name. should be const
size_t *JoinedDimenOffsetArray = JoinedDimArray[JDAIdx][WriterRank];

for (int i = 0; i < Control->ControlCount; i++)
{
Expand Down Expand Up @@ -2002,14 +1992,20 @@ BP5Deserializer::~BP5Deserializer()
{
delete m_FreeableMBA;
}
if (m_FreeableJDOA)
{
delete m_FreeableJDOA;
}
for (auto &step : MetadataBaseArray)
{
delete step;
}
for (auto &pvec : JoinedDimArray)
{
for (auto &p : pvec)
{
if (p)
{
free(p);
}
}
}
}

void *BP5Deserializer::GetMetadataBase(BP5VarRec *VarRec, size_t Step, size_t WriterRank) const
Expand Down
8 changes: 3 additions & 5 deletions source/adios2/toolkit/format/bp5/BP5Deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,16 @@ class BP5Deserializer : virtual public BP5Base
nullptr; // may be a pointer into MetadataBaseArray or m_FreeableMBA
std::vector<void *> *m_FreeableMBA = nullptr;

std::vector<void *> *m_JoinedDimenOffsetArrays = nullptr;
std::vector<void *> *m_FreeableJDOA = nullptr;

// for random access mode, for each timestep, for each writerrank, what
// metameta info applies to the metadata
std::vector<std::vector<ControlInfo *>> m_ControlArray;
// for random access mode, for each timestep, for each writerrank, base
// address of the metadata
std::vector<std::vector<void *> *> MetadataBaseArray;
// for random access mode, for each timestep, for each writerrank, base
// address of the joined dim arrays
std::vector<std::vector<void *> *> JoinedDimArray;
// address of the joined dim arrays, for streaming use 0 index
std::vector<std::vector<size_t *>> JoinedDimArray;
size_t JDAIdx = 0;

ControlInfo *ControlBlocks = nullptr;
ControlInfo *GetPriorControl(FMFormat Format);
Expand Down
Loading