]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-92804: Fix memory leak in memoryview iterator (gh-92805)
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Sat, 14 May 2022 14:24:20 +0000 (19:54 +0530)
committerGitHub <noreply@github.com>
Sat, 14 May 2022 14:24:20 +0000 (23:24 +0900)
Misc/NEWS.d/next/Core and Builtins/2022-05-14-13-22-11.gh-issue-92804.rAqpI2.rst [new file with mode: 0644]
Objects/memoryobject.c
Objects/object.c

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 (file)
index 0000000..7a5fd3f
--- /dev/null
@@ -0,0 +1 @@
+Fix memory leak in ``memoryview`` iterator as it was not finalized at exit. Patch by Kumar Aditya.
index 45fe8985c2adb4126c1e770041a12b80ab925022..8c26916882447131900cdab76fff52ea68617d63 100644 (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),
index 8339ab392fcaee7231c07291ffbf82dd79a107e8..c9bb60eaed87c1a7cd03e68e57e1ffdb5d7d7076 100644 (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,