[Python-checkins] cpython (3.2): Plug a leak in timemodule. The module dictionary is saved during
gregory.p.smith
python-checkins at python.org
Tue Nov 27 19:17:09 CET 2012
http://hg.python.org/cpython/rev/478492476b1f
changeset: 80606:478492476b1f
branch: 3.2
parent: 80603:565c3bbed7d3
user: Gregory P. Smith <greg at krypto.org>
date: Tue Nov 27 10:16:55 2012 -0800
summary:
Plug a leak in timemodule. The module dictionary is saved during
initialization. If the interpreter is shut down and reinitialized (embedded
CPython), the old module dictionary was not dec-refed during the next import of
the time extension module.
Contributed by Torsten Marek of Google.
files:
Misc/NEWS | 3 +++
Modules/timemodule.c | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -620,6 +620,9 @@
Extension Modules
-----------------
+- Fix the leak of a dict in the time module when used in an embedded
+ interpreter that is repeatedly initialized and shutdown and reinitialized.
+
- Issue #16012: Fix a regression in pyexpat. The parser's UseForeignDTD()
method doesn't require an argument again.
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -63,7 +63,7 @@
static double floattime(void);
/* For Y2K check */
-static PyObject *moddict;
+static PyObject *moddict = NULL;
static PyObject *
time_time(PyObject *self, PyObject *unused)
@@ -941,6 +941,11 @@
/* Accept 2-digit dates unless PYTHONY2K is set and non-empty */
p = Py_GETENV("PYTHONY2K");
PyModule_AddIntConstant(m, "accept2dyear", (long) (!p || !*p));
+ /* If an embedded interpreter is shutdown and reinitialized the old
+ moddict was not decrefed on shutdown and the next import of this
+ module leads to a leak. Conditionally decref here to prevent that.
+ */
+ Py_XDECREF(moddict);
/* Squirrel away the module's dictionary for the y2k check */
moddict = PyModule_GetDict(m);
Py_INCREF(moddict);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list