From 45eab946a74596bf9f87dea15e5c3cee4ae74944 Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Wed, 11 Sep 2024 17:44:52 -0700 Subject: [PATCH 1/2] Fix behavior of and memory leak from getAllElements functions. The sublist wasn't being deleted, and its contents weren't being transferred. --- src/sbml/packages/render/sbml/ListOfGlobalRenderInformation.cpp | 2 ++ src/sbml/packages/render/sbml/ListOfLocalRenderInformation.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/sbml/packages/render/sbml/ListOfGlobalRenderInformation.cpp b/src/sbml/packages/render/sbml/ListOfGlobalRenderInformation.cpp index 5e7a877ea..3c8375f0a 100644 --- a/src/sbml/packages/render/sbml/ListOfGlobalRenderInformation.cpp +++ b/src/sbml/packages/render/sbml/ListOfGlobalRenderInformation.cpp @@ -789,6 +789,8 @@ ListOfGlobalRenderInformation::getAllElements(ElementFilter* filter) { List* ret = new List(); List* sublist = ListOf::getAllElements(filter); + ret->transferFrom(sublist); + delete sublist; ADD_FILTERED_POINTER(ret, sublist, mDefaultValues, filter); diff --git a/src/sbml/packages/render/sbml/ListOfLocalRenderInformation.cpp b/src/sbml/packages/render/sbml/ListOfLocalRenderInformation.cpp index 07e18eda2..32f73f3cc 100644 --- a/src/sbml/packages/render/sbml/ListOfLocalRenderInformation.cpp +++ b/src/sbml/packages/render/sbml/ListOfLocalRenderInformation.cpp @@ -760,6 +760,8 @@ ListOfLocalRenderInformation::getAllElements(ElementFilter* filter) { List* ret = new List(); List* sublist = ListOf::getAllElements(filter); + ret->transferFrom(sublist); + delete sublist; ADD_FILTERED_POINTER(ret, sublist, mDefaultValues, filter); From 00407eb96fc6a3b00bf72fa50af0ac74c2249eee Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Wed, 11 Sep 2024 20:41:42 -0700 Subject: [PATCH 2/2] Fix RenderGroup leaks. --- src/sbml/packages/render/sbml/Style.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sbml/packages/render/sbml/Style.cpp b/src/sbml/packages/render/sbml/Style.cpp index e126f2890..84db2c734 100644 --- a/src/sbml/packages/render/sbml/Style.cpp +++ b/src/sbml/packages/render/sbml/Style.cpp @@ -601,6 +601,7 @@ Style::createGroup() delete renderns; this->setGroup(g); + delete g; connectToChild(); @@ -1280,6 +1281,7 @@ Style::createObject(XMLInputStream& stream) RenderGroup* g = new RenderGroup(renderns); g->setElementName(name); setGroup(g); + delete g; obj = &mGroup; }