Skip to content

Commit

Permalink
Merge pull request #43 from rouault/dfa_buildsyntax_tree_memleak
Browse files Browse the repository at this point in the history
[XERCESC-2230] DFAContentModel::buildSyntaxTree(): fix memory leaks when OutOfMemoryException occurs
  • Loading branch information
rleigh-codelibre authored Nov 17, 2021
2 parents ecdc077 + cb4b4cf commit 8ac9637
Showing 1 changed file with 36 additions and 24 deletions.
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

0 comments on commit 8ac9637

Please sign in to comment.