From 8c01a4b27e38fcf0c14a9543f1f04e28e3efd089 Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Fri, 10 Jul 2026 20:50:51 -0700 Subject: [PATCH] Fix memory leak. 'addAssociation' cloned and added the object; now we call 'appendAndOwn' directly so a) we don't leak, and b) we're more efficient. Still need to delete the object on failure. --- src/sbml/packages/fbc/sbml/GeneProductAssociation.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sbml/packages/fbc/sbml/GeneProductAssociation.cpp b/src/sbml/packages/fbc/sbml/GeneProductAssociation.cpp index e09375335c..7d89cc7b7b 100644 --- a/src/sbml/packages/fbc/sbml/GeneProductAssociation.cpp +++ b/src/sbml/packages/fbc/sbml/GeneProductAssociation.cpp @@ -282,7 +282,8 @@ FbcAssociation* GeneProductAssociation::getFbcAssociationFor(const ASTNode* astn delete fbcand; return NULL; } - if (fbcand->addAssociation(child_fbca) != LIBSBML_OPERATION_SUCCESS) { + if (fbcand->getListOfAssociations()->appendAndOwn(child_fbca) != LIBSBML_OPERATION_SUCCESS) { + delete child_fbca; delete fbcand; return NULL; } @@ -296,7 +297,8 @@ FbcAssociation* GeneProductAssociation::getFbcAssociationFor(const ASTNode* astn delete fbcor; return NULL; } - if (fbcor->addAssociation(child_fbca) != LIBSBML_OPERATION_SUCCESS) { + if (fbcor->getListOfAssociations()->appendAndOwn(child_fbca) != LIBSBML_OPERATION_SUCCESS) { + delete child_fbca; delete fbcor; return NULL; }