diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-11-07 00:44:23 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-11-07 00:44:23 (GMT) |
commit | 9684cf69e32ae442c7be54521073ac78557f3bbf (patch) | |
tree | a14fd0f9fbc3bc0f060701c026e785e854944d6f /Lib | |
parent | a6ffec2e88437ed4fecb10cb359cf2fb64781e9a (diff) | |
download | cpython-9684cf69e32ae442c7be54521073ac78557f3bbf.zip cpython-9684cf69e32ae442c7be54521073ac78557f3bbf.tar.gz cpython-9684cf69e32ae442c7be54521073ac78557f3bbf.tar.bz2 |
bpo-31770: Prevent a crash and refleaks when calling sqlite3.Cursor.__init__() more than once (GH-3968) (#4301)
(cherry picked from commit e56ab746a965277ffcc4396d8a0902b6e072d049)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sqlite3/test/regression.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 7dd0050..3ff9abd 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -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") |