Skip to content

Commit 65af44c

Browse files
committed
Fix memory leak
1 parent 5d4c193 commit 65af44c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Python/sysmodule.c

+6-11
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
}
@@ -3216,8 +3216,6 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
32163216
SET_SYS_FROM_STRING("_vpath", VPATH);
32173217
#endif
32183218

3219-
#undef ENSURE_INFO_TYPE
3220-
32213219
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
32223220
#if _PY_SHORT_FLOAT_REPR == 1
32233221
SET_SYS_FROM_STRING("float_repr_style", "short");
@@ -3228,14 +3226,11 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
32283226
SET_SYS("thread_info", PyThread_GetInfo());
32293227

32303228
/* malloc_info */
3231-
if (MallocInfoType == NULL) {
3232-
MallocInfoType = PyStructSequence_NewType(&malloc_info_desc);
3233-
if (MallocInfoType == NULL) {
3234-
goto type_init_failed;
3235-
}
3236-
}
3229+
ENSURE_INFO_TYPE(MallocInfoType, malloc_info_desc);
32373230
SET_SYS("_malloc_info", make_malloc_info());
32383231

3232+
#undef ENSURE_INFO_TYPE
3233+
32393234
/* initialize asyncgen_hooks */
32403235
if (AsyncGenHooksType.tp_name == NULL) {
32413236
if (_PyStructSequence_InitBuiltin(
@@ -3502,7 +3497,7 @@ _PySys_Fini(PyInterpreterState *interp)
35023497
#ifdef __EMSCRIPTEN__
35033498
Py_CLEAR(EmscriptenInfoType);
35043499
#endif
3505-
Py_CLEAR(MallocInfoType);
3500+
_PyStructSequence_FiniType(&MallocInfoType);
35063501
}
35073502
}
35083503

0 commit comments

Comments
 (0)