mirror of
https://github.com/python/cpython.git
synced 2025-07-22 18:55:22 +00:00
bpo-31770: Prevent a crash and refleaks when calling sqlite3.Cursor.__init__() more than once (#3968)
This commit is contained in:
parent
ad455cd924
commit
e56ab746a9
3 changed files with 27 additions and 8 deletions
|
@ -24,6 +24,8 @@
|
|||
import datetime
|
||||
import unittest
|
||||
import sqlite3 as sqlite
|
||||
import weakref
|
||||
from test import support
|
||||
|
||||
class RegressionTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -376,6 +378,22 @@ class RegressionTests(unittest.TestCase):
|
|||
counter += 1
|
||||
self.assertEqual(counter, 3, "should have returned exactly three rows")
|
||||
|
||||
def CheckBpo31770(self):
|
||||
"""
|
||||
The interpreter shouldn't crash in case Cursor.__init__() is called
|
||||
more than once.
|
||||
"""
|
||||
def callback(*args):
|
||||
pass
|
||||
con = sqlite.connect(":memory:")
|
||||
cur = sqlite.Cursor(con)
|
||||
ref = weakref.ref(cur, callback)
|
||||
cur.__init__(con)
|
||||
del cur
|
||||
# The interpreter shouldn't crash when ref is collected.
|
||||
del ref
|
||||
support.gc_collect()
|
||||
|
||||
|
||||
def suite():
|
||||
regression_suite = unittest.makeSuite(RegressionTests, "Check")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue