sbmlteam / libsbml

LibSBML is a native library for reading, writing and manipulating files and data streams containing the Systems Biology Markup Language (SBML). It offers language bindings for C, C++, C#, Java, JavaScript, MATLAB, Perl, PHP, Python, R and Ruby.
https://sbml.org/software/libsbml
Other
38 stars 28 forks source link

CompFlatteningConverter memleak #341

Closed dweindl closed 10 months ago

dweindl commented 10 months ago

Hi, CompFlatteningConverter seems to leak memory:

==91479== 320 (32 direct, 288 indirect) bytes in 1 blocks are definitely lost in loss record 410 of 469
==91479==    at 0x4843FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==91479==    by 0x9D367CA: SBMLDocument::getAllElements(ElementFilter*) (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x9961251: CompFlatteningConverter::unsetExplicitlyListed() (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x9966804: CompFlatteningConverter::performConversion() (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x99655F8: CompFlatteningConverter::convert() (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x992664F: CompSBMLDocumentPlugin::checkConsistency() (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x9D37A88: SBMLDocument::checkConsistency() (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x9542295: _wrap_SBMLDocument_checkConsistency (in lib/python3.11/site-packages/libsbml/_libsbml.cpython-311-x86_64-linux-gnu.so)
==91479==    by 0x54FA7E: ??? (in /usr/bin/python3.11)
==91479==    by 0x547714: PyObject_Vectorcall (in /usr/bin/python3.11)
==91479==    by 0x539DDD: _PyEval_EvalFrameDefault (in /usr/bin/python3.11)
==91479==    by 0x60EC23: ??? (in /usr/bin/python3.11)

Observed with python-libsbml 5.20.1, python3.11, linux

To reproduce:

  1. get https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/release/cases/semantic/01161/01161-sbml-l3v2.xml or any other SBML-comp model
  2. run valgrind --leak-check=full python -c 'import libsbml; sbml_reader = libsbml.SBMLReader(); sbml_doc = sbml_reader.readSBMLFromFile("01161-sbml-l3v2.xml"); sbml_doc.checkConsistency()'
fbergmann commented 10 months ago

@dweindl good catch! just checking, how quickly do you need a new release?

dweindl commented 10 months ago

@fbergmann No rush. I am usually not processing that many models within a single process that it would become a severe problem. Thanks for fixing that.