diff options
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-05-14-13-22-11.gh-issue-92804.rAqpI2.rst | 1 | ||||
-rw-r--r-- | Objects/memoryobject.c | 6 | ||||
-rw-r--r-- | Objects/object.c | 2 |
3 files changed, 6 insertions, 3 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-05-14-13-22-11.gh-issue-92804.rAqpI2.rst b/Misc/NEWS.d/next/Core and Builtins/2022-05-14-13-22-11.gh-issue-92804.rAqpI2.rst new file mode 100644 index 0000000..7a5fd3f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-05-14-13-22-11.gh-issue-92804.rAqpI2.rst @@ -0,0 +1 @@ +Fix memory leak in ``memoryview`` iterator as it was not finalized at exit. Patch by Kumar Aditya. diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 45fe898..8c26916 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -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), diff --git a/Objects/object.c b/Objects/object.c index 8339ab3..c9bb60e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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, |