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
types.GenericAlias should decref instead of using delete in tp_new #88728
Comments
Ref: comment chain at #27008 (comment). setup_ga fails only if PyTuple_Pack fails, which usually happens when Python is out of memory. The cleanup code for setup_ga shouldn't use PyObject_GC_DEL as mentioned in Pablo's comment above. I don't know how to add a test for out of memory, so I'll send a PR without test soon. |
There is the same bug in ga_new(): tp_free is called directly. And is is correct to call deallocator for not initialized GenericAlias object? |
The correct thing to do is to call Py_DECREF so the object is properly unlinked and the other potential cleanups work. Calling the deallocator directly is almost always dangerous. |
But is alias->origin initialized to safely call Py_XDECREF(alias->origin)? |
Why would that be unsafe? PyType_GenericAlloc sets all fields to NULL so that is going to either be NULL or have an object, no? setup_ga only sets alias->origin if there has been no failures |
AFAIK PyType_GenericAlloc is used indirectly in ga_new(), but not in Py_GenericAlias(). |
Oh, I see what you mean, that's a good point. |
That's a good idea :-) The reverted commit caused many segfaults on macOS: 4 tests failed: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: