From 5c2b09e856555e34128113ac99758a776f66ce3c Mon Sep 17 00:00:00 2001
From: Benjamin Peterson <benjamin@python.org>
Date: Tue, 31 May 2011 21:31:37 -0500
Subject: [PATCH] be extra careful with a borrowed reference when the GIL could
 be released (closes #8578)

---
 Modules/_sqlite/connection.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index e4969e36a3..7d12d5ef61 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -200,11 +200,13 @@ void pysqlite_do_all_statements(pysqlite_Connection* self, int action, int reset
         weakref = PyList_GetItem(self->statements, i);
         statement = PyWeakref_GetObject(weakref);
         if (statement != Py_None) {
+            Py_INCREF(statement);
             if (action == ACTION_RESET) {
                 (void)pysqlite_statement_reset((pysqlite_Statement*)statement);
             } else {
                 (void)pysqlite_statement_finalize((pysqlite_Statement*)statement);
             }
+            Py_DECREF(statement);
         }
     }
 
-- 
2.40.0