diff options
author | Gregory P. Smith <greg@krypto.org> | 2012-11-27 18:19:29 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2012-11-27 18:19:29 (GMT) |
commit | 0d68ab3f481ab6c8ecb0d83762b4cd9fb9208356 (patch) | |
tree | bca9b1eceb20e2dad6957ed494bb73519f542656 /Modules/timemodule.c | |
parent | eff174b8b050a0a12e8de2207009acfc49d0cdbc (diff) | |
download | cpython-0d68ab3f481ab6c8ecb0d83762b4cd9fb9208356.zip cpython-0d68ab3f481ab6c8ecb0d83762b4cd9fb9208356.tar.gz cpython-0d68ab3f481ab6c8ecb0d83762b4cd9fb9208356.tar.bz2 |
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.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 397cf8c..13be691 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -96,7 +96,7 @@ static int floatsleep(double); static double floattime(void); /* For Y2K check */ -static PyObject *moddict; +static PyObject *moddict = NULL; /* Exposed in timefuncs.h. */ time_t @@ -858,6 +858,11 @@ inittime(void) /* 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); @@ -1050,5 +1055,3 @@ floatsleep(double secs) return 0; } - - |