From f483b0f3a92d1414efac102d8210dbfd307d037c Mon Sep 17 00:00:00 2001 From: Stefan Krah Date: Sat, 14 Dec 2013 13:43:10 +0100 Subject: [PATCH] Issue #19972: Add rarely used freefunc. This fixes a leak if sys.exit() is used in a program. --- Modules/_pickle.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Modules/_pickle.c b/Modules/_pickle.c index d61c8abb2ff..c52f9451bcb 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -7464,6 +7464,12 @@ pickle_clear(PyObject *m) return 0; } +static void +pickle_free(PyObject *m) +{ + _Pickle_ClearState(_Pickle_GetState(m)); +} + static int pickle_traverse(PyObject *m, visitproc visit, void *arg) { @@ -7485,14 +7491,14 @@ pickle_traverse(PyObject *m, visitproc visit, void *arg) static struct PyModuleDef _picklemodule = { PyModuleDef_HEAD_INIT, - "_pickle", /* m_name */ - pickle_module_doc, /* m_doc */ - sizeof(PickleState), /* m_size */ - pickle_methods, /* m_methods */ - NULL, /* m_reload */ - pickle_traverse, /* m_traverse */ - pickle_clear, /* m_clear */ - NULL /* m_free */ + "_pickle", /* m_name */ + pickle_module_doc, /* m_doc */ + sizeof(PickleState), /* m_size */ + pickle_methods, /* m_methods */ + NULL, /* m_reload */ + pickle_traverse, /* m_traverse */ + pickle_clear, /* m_clear */ + (freefunc)pickle_free /* m_free */ }; PyMODINIT_FUNC