mirror of
https://github.com/python/cpython.git
synced 2025-09-08 01:41:19 +00:00
bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
This commit is contained in:
parent
aec7532ed3
commit
d019bc8319
13 changed files with 105 additions and 19 deletions
|
@ -13,6 +13,7 @@ import subprocess
|
|||
import threading
|
||||
from test.support import unlink
|
||||
import _compression
|
||||
import sys
|
||||
|
||||
|
||||
# Skip tests if the bz2 module doesn't exist.
|
||||
|
@ -816,6 +817,16 @@ class BZ2DecompressorTest(BaseTest):
|
|||
# Previously, a second call could crash due to internal inconsistency
|
||||
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
|
||||
|
||||
@support.refcount_test
|
||||
def test_refleaks_in___init__(self):
|
||||
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
|
||||
bzd = BZ2Decompressor()
|
||||
refs_before = gettotalrefcount()
|
||||
for i in range(100):
|
||||
bzd.__init__()
|
||||
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
|
||||
|
||||
|
||||
class CompressDecompressTest(BaseTest):
|
||||
def testCompress(self):
|
||||
data = bz2.compress(self.TEXT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue