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 leaks due to PySequence_GetItem #13898

Closed
2 tasks done
wwmayer opened this issue May 8, 2024 · 0 comments · Fixed by #13907
Closed
2 tasks done

Memory leaks due to PySequence_GetItem #13898

wwmayer opened this issue May 8, 2024 · 0 comments · Fixed by #13907
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

Comments

@wwmayer
Copy link
Contributor

wwmayer commented May 8, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Problem description

Unlike to PyTuple_GetItem or PyList_GetItem the function PySequence_GetItem returns a new reference instead of a borrowed reference. This means when using the function PySequence_GetItem then for the returned object Py_DECREF or Py_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

Development version

Subproject(s) affected?

None

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@maxwxyz maxwxyz added Bug This issue or PR is related to a bug Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Coding: Python Coding issue related to Python labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants