Skip to content

Commit f6c89bc

Browse files
Fix ref leak in pysqlite_cursor_iternext
1 parent 19f2c47 commit f6c89bc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Modules/_sqlite/cursor.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -802,29 +802,29 @@ PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
802802
if (self->statement) {
803803
rc = pysqlite_step(self->statement->st, self->connection);
804804
if (PyErr_Occurred()) {
805-
(void)pysqlite_statement_reset(self->statement);
806-
Py_DECREF(next_row);
807-
return NULL;
805+
goto error;
808806
}
809807
if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
810-
(void)pysqlite_statement_reset(self->statement);
811-
Py_DECREF(next_row);
812808
_pysqlite_seterror(self->connection->db, NULL);
813-
return NULL;
809+
goto error;
814810
}
815811

816812
if (rc == SQLITE_ROW) {
817813
self->locked = 1; // GH-80254: Prevent recursive use of cursors.
818814
self->next_row = _pysqlite_fetch_one_row(self);
819815
self->locked = 0;
820816
if (self->next_row == NULL) {
821-
(void)pysqlite_statement_reset(self->statement);
822-
return NULL;
817+
goto error;
823818
}
824819
}
825820
}
826821

827822
return next_row;
823+
824+
error:
825+
(void)pysqlite_statement_reset(self->statement);
826+
Py_DECREF(next_row);
827+
return NULL;
828828
}
829829

830830
PyObject* pysqlite_cursor_fetchone(pysqlite_Cursor* self, PyObject* args)

0 commit comments

Comments
 (0)