- Fixed a memory leak in termLocal. This did not cause any problems for

the modelchecker, as it calls it only once, but it caused major
  problems for the arachne engine, which creates and destroys semiruns
  all the time.
This commit is contained in:
ccremers 2004-10-12 15:12:20 +00:00
parent ef34e0080e
commit 0de3320009
3 changed files with 24 additions and 1 deletions

View File

@ -420,6 +420,28 @@ termDuplicate (const Term term)
return newterm; return newterm;
} }
//! Make a deep copy of a term node (one-level)
/**
* Leaves are not copied.
*@return If the original was a leaf, then the pointer is simply returned. Otherwise, new memory is allocated and the node is copied recursively.
*\sa termDuplicateDeep()
*/
Term
termNodeDuplicate (const Term term)
{
Term newterm;
if (term == NULL)
return NULL;
if (realTermLeaf (term))
return term;
newterm = (Term) memAlloc (sizeof (struct term));
memcpy (newterm, term, sizeof (struct term));
return newterm;
}
//! Make a true deep copy of a term. //! Make a true deep copy of a term.
/** /**
* Currently, it this function is not to be used, so we can be sure leaf nodes occur only once in the system. * Currently, it this function is not to be used, so we can be sure leaf nodes occur only once in the system.

View File

@ -158,6 +158,7 @@ int termInTerm (Term t, Term tsub);
void termPrint (Term term); void termPrint (Term term);
void termTuplePrint (Term term); void termTuplePrint (Term term);
Term termDuplicate (const Term term); Term termDuplicate (const Term term);
Term termNodeDuplicate (const Term term);
Term termDuplicateDeep (const Term term); Term termDuplicateDeep (const Term term);
Term termDuplicateUV (Term term); Term termDuplicateUV (Term term);
void termDelete (const Term term); void termDelete (const Term term);

View File

@ -642,7 +642,7 @@ termLocal (Term t, Termlist fromlist, Termlist tolist, const int runid)
} }
else else
{ {
Term newt = termDuplicate (t); Term newt = termNodeDuplicate (t);
if (realTermTuple (t)) if (realTermTuple (t))
{ {
newt->left.op1 = termLocal (t->left.op1, fromlist, tolist, runid); newt->left.op1 = termLocal (t->left.op1, fromlist, tolist, runid);