Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory error in generated FMUs #229

Open
dddvision opened this issue Feb 27, 2025 · 0 comments
Open

Memory error in generated FMUs #229

dddvision opened this issue Feb 27, 2025 · 0 comments

Comments

@dddvision
Copy link

dddvision commented Feb 27, 2025

It seems that all FMUs generated with pythonfmu exhibit a similar memory error. For example, using Resistor.fmu on Ubuntu 20.04 with Python3.12, the memory error can be observed as follows:

Create Resistor_memory_error.py:

from fmpy import read_model_description, extract
from fmpy.fmi2 import FMU2Slave
import shutil

def load_fmu(file_path):
    model_description = read_model_description(file_path, validate=True)
    unzipdir = extract(file_path)
    fmu = FMU2Slave(guid=model_description.guid, unzipDirectory=unzipdir, modelIdentifier=model_description.coSimulation.modelIdentifier)
    fmu.instantiate()
    fmu.terminate()
    fmu.freeInstance()
    shutil.rmtree(unzipdir, ignore_errors=False)

load_fmu("Resistor.fmu")

Run valgrind:

valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file="fmu_memory_use.log" Resistor_memory_error.py

Observe result in fmu_memory_use.log:

==10839== Invalid read of size 4
==10839==    at 0x1C479932: finalizePythonInterpreter (in /tmp/tmpmz0zx7v4/binaries/linux64/Resistor.so)
==10839==    by 0x4011F6A: _dl_fini (dl-fini.c:138)
==10839==    by 0x4F7F8A6: __run_exit_handlers (exit.c:108)
==10839==    by 0x4F7FA5F: exit (exit.c:139)
==10839==    by 0x4F5D089: (below main) (libc-start.c:342)
==10839==  Address 0x6a84a18 is 8 bytes inside a block of size 128 free'd
==10839==    at 0x483CFBF: operator delete(void*) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==10839==    by 0x4F7F8A6: __run_exit_handlers (exit.c:108)
==10839==    by 0x4F7FA5F: exit (exit.c:139)
==10839==    by 0x4F5D089: (below main) (libc-start.c:342)
==10839==  Block was alloc'd at
==10839==    at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==10839==    by 0x1C47ED79: CppfmuInstantiateSlave(char const*, char const*, char const*, char const*, double, int, int, cppfmu::Memory, cppfmu::Logger const&) (in /tmp/tmpmz0zx7v4/binaries/linux64/Resistor.so)
==10839==    by 0x1C47620F: fmi2Instantiate (in /tmp/tmpmz0zx7v4/binaries/linux64/Resistor.so)
==10839==    by 0x4F31FF4: ??? (in /usr/lib/x86_64-linux-gnu/libffi.so.7.1.0)
==10839==    by 0x4F31409: ??? (in /usr/lib/x86_64-linux-gnu/libffi.so.7.1.0)
==10839==    by 0x5E32BA6: _call_function_pointer (callproc.c:931)
==10839==    by 0x5E32BA6: _ctypes_callproc (callproc.c:1273)
==10839==    by 0x5E318EB: PyCFuncPtr_call (_ctypes.c:4173)
==10839==    by 0x4A7165D: PyObject_Call (object.h:705)
==10839==    by 0x4ADFAC1: _PyEval_EvalFrameDefault (bytecodes.c:3263)
==10839==    by 0x4B7CEE5: PyEval_EvalCode (ceval.c:578)
==10839==    by 0x4B9E8B0: run_eval_code_obj (pythonrun.c:1722)
==10839==    by 0x4B9E82A: run_mod (pythonrun.c:1743)
@dddvision dddvision changed the title Memory leak in generated FMUs Memory error in generated FMUs Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant