Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3e1ef1

Browse files
committed
Issue #19437: Fix pysqlite_connection_call() of sqlite3, return NULL when
PyList_Append() fails
1 parent dd4b299 commit b3e1ef1

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

Modules/_sqlite/connection.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,9 +1229,8 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
12291229
return NULL;
12301230
}
12311231

1232-
if (!PyArg_ParseTuple(args, "O", &sql)) {
1232+
if (!PyArg_ParseTuple(args, "O", &sql))
12331233
return NULL;
1234-
}
12351234

12361235
_pysqlite_drop_unused_statement_references(self);
12371236

@@ -1247,7 +1246,6 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
12471246
statement->in_weakreflist = NULL;
12481247

12491248
rc = pysqlite_statement_create(statement, self, sql);
1250-
12511249
if (rc != SQLITE_OK) {
12521250
if (rc == PYSQLITE_TOO_MUCH_SQL) {
12531251
PyErr_SetString(pysqlite_Warning, "You can only execute one statement at a time.");
@@ -1257,25 +1255,23 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
12571255
(void)pysqlite_statement_reset(statement);
12581256
_pysqlite_seterror(self->db, NULL);
12591257
}
1258+
goto error;
1259+
}
12601260

1261-
Py_CLEAR(statement);
1262-
} else {
1263-
weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
1264-
if (!weakref) {
1265-
Py_CLEAR(statement);
1266-
goto error;
1267-
}
1268-
1269-
if (PyList_Append(self->statements, weakref) != 0) {
1270-
Py_CLEAR(weakref);
1271-
goto error;
1272-
}
1273-
1261+
weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
1262+
if (weakref == NULL)
1263+
goto error;
1264+
if (PyList_Append(self->statements, weakref) != 0) {
12741265
Py_DECREF(weakref);
1266+
goto error;
12751267
}
1268+
Py_DECREF(weakref);
12761269

1277-
error:
12781270
return (PyObject*)statement;
1271+
1272+
error:
1273+
Py_DECREF(statement);
1274+
return NULL;
12791275
}
12801276

12811277
PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)

0 commit comments

Comments
 (0)