summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-27 15:57:07 (GMT)
committerGitHub <noreply@github.com>2017-11-27 15:57:07 (GMT)
commitc9758784eb321fb9771e0bc7205b296e4d658045 (patch)
tree1436050bd6f4c967283112fd0fa7b6ffe96af2b0 /Python
parent21c7730761e2a768e33b89b063a095d007dcfd2c (diff)
downloadcpython-c9758784eb321fb9771e0bc7205b296e4d658045.zip
cpython-c9758784eb321fb9771e0bc7205b296e4d658045.tar.gz
cpython-c9758784eb321fb9771e0bc7205b296e4d658045.tar.bz2
bpo-27535: Fix memory leak with warnings ignore (#4489)
The warnings module doesn't leak memory anymore in the hidden warnings registry for the "ignore" action of warnings filters. The warn_explicit() function doesn't add the warning key to the registry anymore for the "ignore" action.
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 27f5b81..2937036 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -528,16 +528,21 @@ warn_explicit(PyObject *category, PyObject *message,
goto cleanup;
}
+ if (_PyUnicode_EqualToASCIIString(action, "ignore")) {
+ goto return_none;
+ }
+
/* Store in the registry that we've been here, *except* when the action
is "always". */
rc = 0;
if (!_PyUnicode_EqualToASCIIString(action, "always")) {
if (registry != NULL && registry != Py_None &&
- PyDict_SetItem(registry, key, Py_True) < 0)
+ PyDict_SetItem(registry, key, Py_True) < 0)
+ {
goto cleanup;
- else if (_PyUnicode_EqualToASCIIString(action, "ignore"))
- goto return_none;
- else if (_PyUnicode_EqualToASCIIString(action, "once")) {
+ }
+
+ if (_PyUnicode_EqualToASCIIString(action, "once")) {
if (registry == NULL || registry == Py_None) {
registry = get_once_registry();
if (registry == NULL)