Issue #20437: Fixed 43 potential bugs when deleting objects references.
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 59966da..7a8a5a1 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -369,8 +369,7 @@
         if (self->apsw_connection) {
             ret = PyObject_CallMethod(self->apsw_connection, "close", "");
             Py_XDECREF(ret);
-            Py_XDECREF(self->apsw_connection);
-            self->apsw_connection = NULL;
+            Py_CLEAR(self->apsw_connection);
             self->db = NULL;
         } else {
             Py_BEGIN_ALLOW_THREADS