From 0de3320009f60d376660c2c5f335195acc3ca7eb Mon Sep 17 00:00:00 2001 From: ccremers Date: Tue, 12 Oct 2004 15:12:20 +0000 Subject: [PATCH] - 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. --- src/term.c | 22 ++++++++++++++++++++++ src/term.h | 1 + src/termlist.c | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/term.c b/src/term.c index 00890e1..77fe57f 100644 --- a/src/term.c +++ b/src/term.c @@ -420,6 +420,28 @@ termDuplicate (const Term term) 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. /** * Currently, it this function is not to be used, so we can be sure leaf nodes occur only once in the system. diff --git a/src/term.h b/src/term.h index 72da251..33e8866 100644 --- a/src/term.h +++ b/src/term.h @@ -158,6 +158,7 @@ int termInTerm (Term t, Term tsub); void termPrint (Term term); void termTuplePrint (Term term); Term termDuplicate (const Term term); +Term termNodeDuplicate (const Term term); Term termDuplicateDeep (const Term term); Term termDuplicateUV (Term term); void termDelete (const Term term); diff --git a/src/termlist.c b/src/termlist.c index 57bd39e..943d5e2 100644 --- a/src/termlist.c +++ b/src/termlist.c @@ -642,7 +642,7 @@ termLocal (Term t, Termlist fromlist, Termlist tolist, const int runid) } else { - Term newt = termDuplicate (t); + Term newt = termNodeDuplicate (t); if (realTermTuple (t)) { newt->left.op1 = termLocal (t->left.op1, fromlist, tolist, runid);