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

[XERCESC-2230] DFAContentModel::buildSyntaxTree(): fix memory leaks when OutOfMemoryException occurs #43

Merged
Merged
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
60 changes: 36 additions & 24 deletions src/xercesc/validators/common/DFAContentModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,33 +1498,45 @@ CMNode* DFAContentModel::buildSyntaxTree(ContentSpecNode* const curNode
retNode = buildSyntaxTree(cursor, curIndex);
for(unsigned int i=0;i<nLoopCount;i++)
{
CMNode* newRight = buildSyntaxTree(rightNode, curIndex);
//
// Now handle our level. We use our left child's last pos set and our
// right child's first pos set, so get them now for convenience.
//
const CMStateSet& last = retNode->getLastPos();
const CMStateSet& first = newRight->getFirstPos();
CMNode* newRight = nullptr;
try
{
newRight = buildSyntaxTree(rightNode, curIndex);

//
// Now, for every position which is in our left child's last set
// add all of the states in our right child's first set to the
// follow set for that position.
//
CMStateSetEnumerator enumLast(&last);
while(enumLast.hasMoreElements())
//
// Now handle our level. We use our left child's last pos set and our
// right child's first pos set, so get them now for convenience.
//
const CMStateSet& last = retNode->getLastPos();
const CMStateSet& first = newRight->getFirstPos();

//
// Now, for every position which is in our left child's last set
// add all of the states in our right child's first set to the
// follow set for that position.
//
CMStateSetEnumerator enumLast(&last);
while(enumLast.hasMoreElements())
{
XMLSize_t index=enumLast.nextElement();
*fFollowList[index] |= first;
}

retNode = new (fMemoryManager) CMBinaryOp
(
ContentSpecNode::Sequence
, retNode
, newRight
, fLeafCount
, fMemoryManager
);
}
catch( const OutOfMemoryException& )
{
XMLSize_t index=enumLast.nextElement();
*fFollowList[index] |= first;
delete newRight;
delete retNode;
throw;
}
retNode = new (fMemoryManager) CMBinaryOp
(
ContentSpecNode::Sequence
, retNode
, newRight
, fLeafCount
, fMemoryManager
);
}
return retNode;
}
Expand Down