diff options
author | Yury Selivanov <yury@magic.io> | 2016-11-09 23:55:45 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-11-09 23:55:45 (GMT) |
commit | 46a02db90b295bfec1712515e09aeda31bbe84e0 (patch) | |
tree | f9c528e4230c67e830ea1eadd176a0a22b63b14d /Modules/_functoolsmodule.c | |
parent | 28f42fd4f813b4be15b47629c557ef8f958727cb (diff) | |
download | cpython-46a02db90b295bfec1712515e09aeda31bbe84e0.zip cpython-46a02db90b295bfec1712515e09aeda31bbe84e0.tar.gz cpython-46a02db90b295bfec1712515e09aeda31bbe84e0.tar.bz2 |
Issue #28653: Fix a refleak in functools.lru_cache.
Diffstat (limited to 'Modules/_functoolsmodule.c')
-rw-r--r-- | Modules/_functoolsmodule.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index d785c49..9c9ab5f 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); |