Skip to content

Commit f56577e

Browse files
committed
Fix memory leak
1 parent 5246ef8 commit f56577e

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Python/sysmodule.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ PyDoc_STRVAR(malloc_info__doc__,
19441944
\n\
19451945
Memory allocator info as a named tuple.");
19461946

1947-
static PyTypeObject *MallocInfoType;
1947+
static PyTypeObject MallocInfoType;
19481948

19491949
static PyStructSequence_Field malloc_info_fields[] = {
19501950
{"allocator", "current memory allocator"},
@@ -1970,7 +1970,7 @@ make_malloc_info(void)
19701970
PyObject *v;
19711971
int pos = 0;
19721972

1973-
malloc_info = PyStructSequence_New(MallocInfoType);
1973+
malloc_info = PyStructSequence_New(&MallocInfoType);
19741974
if (malloc_info == NULL) {
19751975
return NULL;
19761976
}
@@ -3139,8 +3139,6 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
31393139
SET_SYS_FROM_STRING("_vpath", VPATH);
31403140
#endif
31413141

3142-
#undef ENSURE_INFO_TYPE
3143-
31443142
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
31453143
#if _PY_SHORT_FLOAT_REPR == 1
31463144
SET_SYS_FROM_STRING("float_repr_style", "short");
@@ -3151,14 +3149,11 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
31513149
SET_SYS("thread_info", PyThread_GetInfo());
31523150

31533151
/* malloc_info */
3154-
if (MallocInfoType == NULL) {
3155-
MallocInfoType = PyStructSequence_NewType(&malloc_info_desc);
3156-
if (MallocInfoType == NULL) {
3157-
goto type_init_failed;
3158-
}
3159-
}
3152+
ENSURE_INFO_TYPE(MallocInfoType, malloc_info_desc);
31603153
SET_SYS("_malloc_info", make_malloc_info());
31613154

3155+
#undef ENSURE_INFO_TYPE
3156+
31623157
/* initialize asyncgen_hooks */
31633158
if (AsyncGenHooksType.tp_name == NULL) {
31643159
if (_PyStructSequence_InitBuiltin(
@@ -3425,7 +3420,7 @@ _PySys_Fini(PyInterpreterState *interp)
34253420
#ifdef __EMSCRIPTEN__
34263421
Py_CLEAR(EmscriptenInfoType);
34273422
#endif
3428-
Py_CLEAR(MallocInfoType);
3423+
_PyStructSequence_FiniType(&MallocInfoType);
34293424
}
34303425
}
34313426

0 commit comments

Comments
 (0)