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
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index f06f92c..3b84484 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -231,8 +231,7 @@
if (converter != Py_None) {
Py_DECREF(converter);
}
- Py_XDECREF(self->row_cast_map);
- self->row_cast_map = NULL;
+ Py_CLEAR(self->row_cast_map);
return -1;
}
@@ -468,8 +467,7 @@
allow_8bit_chars = ((self->connection->text_factory != (PyObject*)&PyUnicode_Type) &&
(self->connection->text_factory != pysqlite_OptimizedUnicode));
- Py_XDECREF(self->next_row);
- self->next_row = NULL;
+ Py_CLEAR(self->next_row);
if (multiple) {
/* executemany() */
@@ -896,8 +894,7 @@
if (!self->next_row) {
if (self->statement) {
(void)pysqlite_statement_reset(self->statement);
- Py_DECREF(self->statement);
- self->statement = NULL;
+ Py_CLEAR(self->statement);
}
return NULL;
}