Skip to content

Commit 9983345

Browse files
Fix refcounting during groupby key comparison
1 parent e3a54be commit 9983345

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Modules/itertoolsmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,15 @@ groupby_next(PyObject *op)
550550

551551
/* Hold strong references during comparison to prevent re-entrant __eq__
552552
from advancing the iterator and invalidating borrowed references. */
553-
Py_INCREF(gbo -> tgtkey);
554-
Py_INCREF(gbo -> currkey);
553+
PyObject *tgtkey = gbo->tgtkey;
554+
PyObject *currkey = gbo->currkey;
555+
Py_INCREF(tgtkey);
556+
Py_INCREF(currkey);
555557

556558
rcmp = PyObject_RichCompareBool(tgtkey, currkey, Py_EQ);
557559

558-
Py_DECREF(gbo -> tgtkey);
559-
Py_DECREF(gbo -> currkey);
560+
Py_DECREF(tgtkey);
561+
Py_DECREF(currkey);
560562

561563
if (rcmp == -1)
562564
return NULL;

0 commit comments

Comments
 (0)