Skip to content

Commit f571c26

Browse files
authored
gh-91632: Fix generic_alias_iterator to be finalized at exit. (GH-91727)
1 parent f92bcfe commit f571c26

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a minor memory leak at exit: release the memory of the :class:`generic_alias_iterator` type. Patch by Dong-hee Na.

Objects/genericaliasobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ ga_iter_clear(PyObject *self) {
683683
return 0;
684684
}
685685

686-
static PyTypeObject Py_GenericAliasIterType = {
686+
// gh-91632: _Py_GenericAliasIterType is exported to be cleared
687+
// in _PyTypes_FiniTypes.
688+
PyTypeObject _Py_GenericAliasIterType = {
687689
PyVarObject_HEAD_INIT(&PyType_Type, 0)
688690
.tp_name = "generic_alias_iterator",
689691
.tp_basicsize = sizeof(gaiterobject),
@@ -697,7 +699,7 @@ static PyTypeObject Py_GenericAliasIterType = {
697699

698700
static PyObject *
699701
ga_iter(PyObject *self) {
700-
gaiterobject *gi = PyObject_GC_New(gaiterobject, &Py_GenericAliasIterType);
702+
gaiterobject *gi = PyObject_GC_New(gaiterobject, &_Py_GenericAliasIterType);
701703
if (gi == NULL) {
702704
return NULL;
703705
}

Objects/object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ _PyTypes_InitState(PyInterpreterState *interp)
18341834
#ifdef MS_WINDOWS
18351835
extern PyTypeObject PyHKEY_Type;
18361836
#endif
1837+
extern PyTypeObject _Py_GenericAliasIterType;
18371838

18381839
static PyTypeObject* static_types[] = {
18391840
// The two most important base types: must be initialized first and
@@ -1923,6 +1924,7 @@ static PyTypeObject* static_types[] = {
19231924
&_PyAsyncGenWrappedValue_Type,
19241925
&_PyContextTokenMissing_Type,
19251926
&_PyCoroWrapper_Type,
1927+
&_Py_GenericAliasIterType,
19261928
&_PyHamtItems_Type,
19271929
&_PyHamtKeys_Type,
19281930
&_PyHamtValues_Type,

0 commit comments

Comments
 (0)