Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c67dbd4

Browse filesBrowse files
authored
Add some gc safety around _mysql__fetch_row (PyMySQL#348)
Users of gc.get_referrers() could cause a SystemError to be raised if this function is running in a different python thread.
1 parent 18163d7 commit c67dbd4
Copy full SHA for c67dbd4

File tree

Expand file treeCollapse file tree

1 file changed

+8
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-2
lines changed

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,15 @@ _mysql_ResultObject_fetch_row(
13731373
convert_row = row_converters[how];
13741374
if (maxrows) {
13751375
if (!(r = PyTuple_New(maxrows))) goto error;
1376-
rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows,
1377-
convert_row);
1376+
1377+
// see: https://docs.python.org/3/library/gc.html#gc.get_referrers
1378+
// This function can get a reference to the tuple r, and if that
1379+
// code is preempted while holding a ref to r, the _PyTuple_Resize
1380+
// will raise a SystemError because the ref count is 2.
1381+
PyObject_GC_UnTrack(r);
1382+
rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows, convert_row);
13781383
if (rowsadded == -1) goto error;
1384+
PyObject_GC_Track(r);
13791385
} else {
13801386
if (self->use) {
13811387
maxrows = 1000;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.