Memory leaks due to PySequence_GetItem #13898
Labels
Bug
This issue or PR is related to a bug
Coding: Python
Coding issue related to Python
Core
Issue or PR touches core sections (App, Gui, Base) of FreeCAD
Is there an existing issue for this?
Problem description
Unlike to
PyTuple_GetItem
orPyList_GetItem
the functionPySequence_GetItem
returns a new reference instead of a borrowed reference. This means when using the functionPySequence_GetItem
then for the returned objectPy_DECREF
orPy_XDECREF
must be called to decrease the reference counter.Because this isn't done anywhere in the FreeCAD code where this function is used it causes memory leaks. It's recommended to use the class Py::Sequence instead.
See:
https://docs.python.org/3/c-api/tuple.html#c.PyTuple_GetItem
https://docs.python.org/3/c-api/list.html#c.PyList_GetItem
https://docs.python.org/3/c-api/sequence.html#c.PySequence_GetItem
Full version info
Subproject(s) affected?
None
Anything else?
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: