Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8c3f96e0
Commit
8c3f96e0
authored
Nov 09, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28653: Fix a refleak in functools.lru_cache.
parent
a027cca6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
2 deletions
+27
-2
Lib/test/test_functools.py
Lib/test/test_functools.py
+19
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_functoolsmodule.c
Modules/_functoolsmodule.c
+6
-2
No files found.
Lib/test/test_functools.py
View file @
8c3f96e0
...
...
@@ -1162,6 +1162,25 @@ class TestLRU:
self
.
assertEqual
(
misses
,
4
)
self
.
assertEqual
(
currsize
,
2
)
def
test_lru_type_error
(
self
):
# Regression test for issue #28653.
# lru_cache was leaking when one of the arguments
# wasn't cacheable.
@
functools
.
lru_cache
(
maxsize
=
None
)
def
infinite_cache
(
o
):
pass
@
functools
.
lru_cache
(
maxsize
=
10
)
def
limited_cache
(
o
):
pass
with
self
.
assertRaises
(
TypeError
):
infinite_cache
([])
with
self
.
assertRaises
(
TypeError
):
limited_cache
([])
def
test_lru_with_maxsize_none
(
self
):
@
self
.
module
.
lru_cache
(
maxsize
=
None
)
def
fib
(
n
):
...
...
Misc/NEWS
View file @
8c3f96e0
...
...
@@ -457,6 +457,8 @@ Library
- Issue #28652: Make loop methods reject socket kinds they do not support.
- Issue #28653: Fix a refleak in functools.lru_cache.
IDLE
----
...
...
Modules/_functoolsmodule.c
View file @
8c3f96e0
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment