aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_hashlib.py
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2018-02-13 12:28:33 +0200
committerINADA Naoki <methane@users.noreply.github.com>2018-02-13 19:28:33 +0900
commitd019bc8319ea35e93bf4baa38098ff1b57cd3ee5 (patch)
treed9b927eba02059f8be8465d35b6969254b172b8e /Lib/test/test_hashlib.py
parentaec7532ed3ccbd29d3429a3f375e25f956c44003 (diff)
downloadcpython-d019bc8319ea35e93bf4baa38098ff1b57cd3ee5.tar.gz
cpython-d019bc8319ea35e93bf4baa38098ff1b57cd3ee5.zip
bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
Diffstat (limited to 'Lib/test/test_hashlib.py')
-rw-r--r--Lib/test/test_hashlib.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 751f74813d3..f7df872793c 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -162,6 +162,15 @@ class HashLibTestCase(unittest.TestCase):
constructors = self.constructors_to_test.values()
return itertools.chain.from_iterable(constructors)
+ @support.refcount_test
+ def test_refleaks_in_hash___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ sha1_hash = c_hashlib.new('sha1')
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ sha1_hash.__init__('sha1')
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
def test_hash_array(self):
a = array.array("b", range(10))
for cons in self.hash_constructors: