GH-92804: Fix memory leak in memoryview iterator (gh-92805)

This commit is contained in:
Kumar Aditya 2022-05-14 19:54:20 +05:30 committed by GitHub
parent 2e8f721c0f
commit d923fdf54b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View File

@ -0,0 +1 @@
Fix memory leak in ``memoryview`` iterator as it was not finalized at exit. Patch by Kumar Aditya.

View File

@ -3156,7 +3156,7 @@ static PyMethodDef memory_methods[] = {
/* Memoryview Iterator */
/**************************************************************************/
static PyTypeObject PyMemoryIter_Type;
PyTypeObject _PyMemoryIter_Type;
typedef struct {
PyObject_HEAD
@ -3233,7 +3233,7 @@ memory_iter(PyObject *seq)
}
memoryiterobject *it;
it = PyObject_GC_New(memoryiterobject, &PyMemoryIter_Type);
it = PyObject_GC_New(memoryiterobject, &_PyMemoryIter_Type);
if (it == NULL) {
return NULL;
}
@ -3246,7 +3246,7 @@ memory_iter(PyObject *seq)
return (PyObject *)it;
}
static PyTypeObject PyMemoryIter_Type = {
PyTypeObject _PyMemoryIter_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "memory_iterator",
.tp_basicsize = sizeof(memoryiterobject),

View File

@ -1845,6 +1845,7 @@ _PyTypes_InitState(PyInterpreterState *interp)
extern PyTypeObject PyHKEY_Type;
#endif
extern PyTypeObject _Py_GenericAliasIterType;
extern PyTypeObject _PyMemoryIter_Type;
static PyTypeObject* static_types[] = {
// The two most important base types: must be initialized first and
@ -1944,6 +1945,7 @@ static PyTypeObject* static_types[] = {
&_PyHamt_Type,
&_PyInterpreterID_Type,
&_PyManagedBuffer_Type,
&_PyMemoryIter_Type,
&_PyMethodWrapper_Type,
&_PyNamespace_Type,
&_PyNone_Type,