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

PyType_FromSpec may leak memory with repeated slot IDs #93466

Closed
encukou opened this issue Jun 3, 2022 · 0 comments
Closed

PyType_FromSpec may leak memory with repeated slot IDs #93466

encukou opened this issue Jun 3, 2022 · 0 comments
Assignees
Labels
expert-C-API type-bug

Comments

@encukou
Copy link
Member

@encukou encukou commented Jun 3, 2022

If a slot ID is repeated in PyType_Spec, the current PyType_FromSpec implementation happens to usually use the last one and ignore earlier ones, but:

  • if Py_tp_doc is repeated, PyType_FromSpec may leak memory, and
  • if Py_tp_members is repeated, PyType_FromSpec may memcpy unintialized memory (if slot specifies fewer members than the last one).

We chould:

  • clarify in the docs that repeated slot IDs are not supported
  • raise an exception for duplicate slots (at least when it's easy to detect, as in the cases above)

Alternatively, we could formalize that the last slot of a given ID “wins” and fix the leak/mem issue, but I don't see a use case for this more complex behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expert-C-API type-bug
Projects
None yet
Development

No branches or pull requests

1 participant