From 42a8bafd101556956b6e0ed574cdf06f656be3c9 Mon Sep 17 00:00:00 2001 From: Brian Taylor Date: Sat, 24 Jun 2023 18:25:29 -0700 Subject: [PATCH 1/2] Fix some more memory leaks in the CIDER 1D and 2D destroy functions. --- src/ciderlib/oned/onedest.c | 25 ++++++++++++++++++++++++- src/ciderlib/twod/twodest.c | 10 ++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ciderlib/oned/onedest.c b/src/ciderlib/oned/onedest.c index 385f68299..90ee0cc81 100644 --- a/src/ciderlib/oned/onedest.c +++ b/src/ciderlib/oned/onedest.c @@ -53,7 +53,7 @@ ONEdestroy(ONEdevice *pDevice) /* destroy the mesh */ if (pDevice->elemArray) { - for (eIndex = 1; eIndex < pDevice->numNodes-1; eIndex++) { + for (eIndex = 1; eIndex < pDevice->numNodes; eIndex++) { pElem = pDevice->elemArray[eIndex]; pEdge = pElem->pEdge; FREE(pEdge); @@ -67,6 +67,29 @@ ONEdestroy(ONEdevice *pDevice) } FREE(pDevice->elemArray); } + + if (pDevice->pMaterials) { + ONEmaterial* pMtmp = pDevice->pMaterials; + while (pMtmp) { + ONEmaterial* pMtmpnext = pMtmp->next; + FREE(pMtmp); + pMtmp = pMtmpnext; + } + } + + if (pDevice->pFirstContact) { + struct sONEcontact* pFCtmp = pDevice->pFirstContact; + while (pFCtmp) { + struct sONEcontact* pFCtmpnext = pFCtmp->next; + FREE(pFCtmp); + pFCtmp = pFCtmpnext; + } + } + + if (pDevice->pStats) { + FREE(pDevice->pStats); + } + /* destroy any other lists */ /* NOT IMPLEMENTED */ diff --git a/src/ciderlib/twod/twodest.c b/src/ciderlib/twod/twodest.c index 01b646c42..2466eea44 100644 --- a/src/ciderlib/twod/twodest.c +++ b/src/ciderlib/twod/twodest.c @@ -90,6 +90,16 @@ TWOdestroy(TWOdevice *pDevice) } } + if (pDevice->pStats) { + FREE(pDevice->pStats); + } + if (pDevice->xScale) { + FREE(pDevice->xScale); + } + if (pDevice->yScale) { + FREE(pDevice->yScale); + } + /* destroy the channels */ /* NOT IMPLEMENTED */ From cbda9ab7b589f3b7b4e20b10230adb8d7c210efc Mon Sep 17 00:00:00 2001 From: Brian Taylor Date: Sun, 25 Jun 2023 08:42:31 -0700 Subject: [PATCH 2/2] The CONTACT statement does not apply to 1D devices. --- src/ciderlib/oned/onedest.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ciderlib/oned/onedest.c b/src/ciderlib/oned/onedest.c index 90ee0cc81..9b1bba8b4 100644 --- a/src/ciderlib/oned/onedest.c +++ b/src/ciderlib/oned/onedest.c @@ -77,15 +77,6 @@ ONEdestroy(ONEdevice *pDevice) } } - if (pDevice->pFirstContact) { - struct sONEcontact* pFCtmp = pDevice->pFirstContact; - while (pFCtmp) { - struct sONEcontact* pFCtmpnext = pFCtmp->next; - FREE(pFCtmp); - pFCtmp = pFCtmpnext; - } - } - if (pDevice->pStats) { FREE(pDevice->pStats); }