Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-99886: Fix crash when freeing objects with managed dictionaries #99902

Merged
merged 7 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_sqlite3/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ def test_executescript_step_through_select(self):
con.executescript("select step(t) from t")
self.assertEqual(steps, values)

def test_custom_cursor_object_crash_gh_99886(self):
# This test segfaults on GH-99886
class MyCursor(sqlite3.Cursor):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# this can go before or after the super call; doesn't matter
self.some_attr = None

conn = sqlite3.connect(':memory:')
cur = conn.cursor(MyCursor)
cur.close()
del cur

class RecursiveUseOfCursors(unittest.TestCase):
# GH-80254: sqlite3 should not segfault for recursive use of cursors.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash when an object which does not have a dictionary frees its instance values.
1 change: 1 addition & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5581,6 +5581,7 @@ _PyObject_FreeInstanceAttributes(PyObject *self)
Py_XDECREF((*values_ptr)->values[i]);
}
free_values(*values_ptr);
*values_ptr = NULL;
Fidget-Spinner marked this conversation as resolved.
Show resolved Hide resolved
}

PyObject *
Expand Down