Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix memory leak
  • Loading branch information
tiran committed Aug 30, 2022
commit 65af44ceef5fbbbe37d99627e70ebc01c185c3d8
17 changes: 6 additions & 11 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ PyDoc_STRVAR(malloc_info__doc__,
\n\
Memory allocator info as a named tuple.");

static PyTypeObject *MallocInfoType;
static PyTypeObject MallocInfoType;

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

malloc_info = PyStructSequence_New(MallocInfoType);
malloc_info = PyStructSequence_New(&MallocInfoType);
if (malloc_info == NULL) {
return NULL;
}
Expand Down Expand Up @@ -3216,8 +3216,6 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS_FROM_STRING("_vpath", VPATH);
#endif

#undef ENSURE_INFO_TYPE

/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
#if _PY_SHORT_FLOAT_REPR == 1
SET_SYS_FROM_STRING("float_repr_style", "short");
Expand All @@ -3228,14 +3226,11 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS("thread_info", PyThread_GetInfo());

/* malloc_info */
if (MallocInfoType == NULL) {
MallocInfoType = PyStructSequence_NewType(&malloc_info_desc);
if (MallocInfoType == NULL) {
goto type_init_failed;
}
}
ENSURE_INFO_TYPE(MallocInfoType, malloc_info_desc);
SET_SYS("_malloc_info", make_malloc_info());

#undef ENSURE_INFO_TYPE

/* initialize asyncgen_hooks */
if (AsyncGenHooksType.tp_name == NULL) {
if (_PyStructSequence_InitBuiltin(
Expand Down Expand Up @@ -3502,7 +3497,7 @@ _PySys_Fini(PyInterpreterState *interp)
#ifdef __EMSCRIPTEN__
Py_CLEAR(EmscriptenInfoType);
#endif
Py_CLEAR(MallocInfoType);
_PyStructSequence_FiniType(&MallocInfoType);
}
}

Expand Down