Skip to content

Commit

Permalink
GH-92804: Fix memory leak in memoryview iterator (gh-92805)
Browse files Browse the repository at this point in the history
(cherry picked from commit d923fdf)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
  • Loading branch information
miss-islington and kumaraditya303 authored May 14, 2022
1 parent 9640676 commit d9089c0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix memory leak in ``memoryview`` iterator as it was not finalized at exit. Patch by Kumar Aditya.
6 changes: 3 additions & 3 deletions Objects/memoryobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,7 @@ static PyMethodDef memory_methods[] = {
/* Memoryview Iterator */
/**************************************************************************/

static PyTypeObject PyMemoryIter_Type;
PyTypeObject _PyMemoryIter_Type;

typedef struct {
PyObject_HEAD
Expand Down Expand Up @@ -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;
}
Expand All @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1944,6 +1945,7 @@ static PyTypeObject* static_types[] = {
&_PyHamt_Type,
&_PyInterpreterID_Type,
&_PyManagedBuffer_Type,
&_PyMemoryIter_Type,
&_PyMethodWrapper_Type,
&_PyNamespace_Type,
&_PyNone_Type,
Expand Down

0 comments on commit d9089c0

Please sign in to comment.