summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/cursor.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-11-07 00:44:23 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-11-07 00:44:23 (GMT)
commit9684cf69e32ae442c7be54521073ac78557f3bbf (patch)
treea14fd0f9fbc3bc0f060701c026e785e854944d6f /Modules/_sqlite/cursor.c
parenta6ffec2e88437ed4fecb10cb359cf2fb64781e9a (diff)
downloadcpython-9684cf69e32ae442c7be54521073ac78557f3bbf.zip
cpython-9684cf69e32ae442c7be54521073ac78557f3bbf.tar.gz
cpython-9684cf69e32ae442c7be54521073ac78557f3bbf.tar.bz2
bpo-31770: Prevent a crash and refleaks when calling sqlite3.Cursor.__init__() more than once (GH-3968) (#4301)
(cherry picked from commit e56ab746a965277ffcc4396d8a0902b6e072d049)
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r--Modules/_sqlite/cursor.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 8341fb8..b6257a0 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -39,21 +39,20 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject*
}
Py_INCREF(connection);
- self->connection = connection;
- self->statement = NULL;
- self->next_row = NULL;
- self->in_weakreflist = NULL;
+ Py_XSETREF(self->connection, connection);
+ Py_CLEAR(self->statement);
+ Py_CLEAR(self->next_row);
- self->row_cast_map = PyList_New(0);
+ Py_XSETREF(self->row_cast_map, PyList_New(0));
if (!self->row_cast_map) {
return -1;
}
Py_INCREF(Py_None);
- self->description = Py_None;
+ Py_XSETREF(self->description, Py_None);
Py_INCREF(Py_None);
- self->lastrowid= Py_None;
+ Py_XSETREF(self->lastrowid, Py_None);
self->arraysize = 1;
self->closed = 0;
@@ -62,7 +61,7 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject*
self->rowcount = -1L;
Py_INCREF(Py_None);
- self->row_factory = Py_None;
+ Py_XSETREF(self->row_factory, Py_None);
if (!pysqlite_check_thread(self->connection)) {
return -1;