summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-11-09 18:55:45 -0500
committerYury Selivanov <yury@magic.io>2016-11-09 18:55:45 -0500
commit5b838447e04990422cc4efb7ae069e090b3ef8b8 (patch)
treeaa8831ce40e2405bbd07aa930e426307e9ffa8c3 /Modules
parentc823f3ffde59b90df6ef240ece057d4da20e580e (diff)
downloadcpython-5b838447e04990422cc4efb7ae069e090b3ef8b8.tar.gz
Issue #28653: Fix a refleak in functools.lru_cache.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_functoolsmodule.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index d785c4932b..9c9ab5f8ea 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -781,8 +781,10 @@ infinite_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwd
if (!key)
return NULL;
hash = PyObject_Hash(key);
- if (hash == -1)
+ if (hash == -1) {
+ Py_DECREF(key);
return NULL;
+ }
result = _PyDict_GetItem_KnownHash(self->cache, key, hash);
if (result) {
Py_INCREF(result);
@@ -837,8 +839,10 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
if (!key)
return NULL;
hash = PyObject_Hash(key);
- if (hash == -1)
+ if (hash == -1) {
+ Py_DECREF(key);
return NULL;
+ }
link = (lru_list_elem *)_PyDict_GetItem_KnownHash(self->cache, key, hash);
if (link) {
lru_cache_extricate_link(link);