Skip to content

Add some gc safety around _mysql__fetch_row #348

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

Merged
merged 3 commits into from
Feb 5, 2020
Merged
Changes from all 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
10 changes: 8 additions & 2 deletions MySQLdb/_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,9 +1343,15 @@ _mysql_ResultObject_fetch_row(
convert_row = row_converters[how];
if (maxrows) {
if (!(r = PyTuple_New(maxrows))) goto error;
rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows,
convert_row);

// see: https://docs.python.org/3/library/gc.html#gc.get_referrers
// This function can get a reference to the tuple r, and if that
// code is preempted while holding a ref to r, the _PyTuple_Resize
// will raise a SystemError because the ref count is 2.
PyObject_GC_UnTrack(r);
rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows, convert_row);
if (rowsadded == -1) goto error;
PyObject_GC_Track(r);
} else {
if (self->use) {
maxrows = 1000;
Expand Down