Issue #3153: sqlite leaks on error.
Changed statements of the form Py_DECREF(obj), obj = 0 to Py_CLEAR(obj).
This commit is contained in:
parent
b93dc5f0ce
commit
bd70476897
|
@ -1014,19 +1014,16 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
|
||||||
_pysqlite_seterror(self->db, NULL);
|
_pysqlite_seterror(self->db, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(statement);
|
Py_CLEAR(statement);
|
||||||
statement = 0;
|
|
||||||
} else {
|
} else {
|
||||||
weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
|
weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
|
||||||
if (!weakref) {
|
if (!weakref) {
|
||||||
Py_DECREF(statement);
|
Py_CLEAR(statement);
|
||||||
statement = 0;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyList_Append(self->statements, weakref) != 0) {
|
if (PyList_Append(self->statements, weakref) != 0) {
|
||||||
Py_DECREF(weakref);
|
Py_CLEAR(weakref);
|
||||||
statement = 0;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1050,15 +1047,13 @@ PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args,
|
||||||
|
|
||||||
method = PyObject_GetAttrString(cursor, "execute");
|
method = PyObject_GetAttrString(cursor, "execute");
|
||||||
if (!method) {
|
if (!method) {
|
||||||
Py_DECREF(cursor);
|
Py_CLEAR(cursor);
|
||||||
cursor = 0;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyObject_CallObject(method, args);
|
result = PyObject_CallObject(method, args);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_DECREF(cursor);
|
Py_CLEAR(cursor);
|
||||||
cursor = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -1081,15 +1076,13 @@ PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* a
|
||||||
|
|
||||||
method = PyObject_GetAttrString(cursor, "executemany");
|
method = PyObject_GetAttrString(cursor, "executemany");
|
||||||
if (!method) {
|
if (!method) {
|
||||||
Py_DECREF(cursor);
|
Py_CLEAR(cursor);
|
||||||
cursor = 0;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyObject_CallObject(method, args);
|
result = PyObject_CallObject(method, args);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_DECREF(cursor);
|
Py_CLEAR(cursor);
|
||||||
cursor = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -1112,15 +1105,13 @@ PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject*
|
||||||
|
|
||||||
method = PyObject_GetAttrString(cursor, "executescript");
|
method = PyObject_GetAttrString(cursor, "executescript");
|
||||||
if (!method) {
|
if (!method) {
|
||||||
Py_DECREF(cursor);
|
Py_CLEAR(cursor);
|
||||||
cursor = 0;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyObject_CallObject(method, args);
|
result = PyObject_CallObject(method, args);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_DECREF(cursor);
|
Py_CLEAR(cursor);
|
||||||
cursor = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
|
@ -545,7 +545,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
|
||||||
}
|
}
|
||||||
rc = pysqlite_statement_create(self->statement, self->connection, operation);
|
rc = pysqlite_statement_create(self->statement, self->connection, operation);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
self->statement = 0;
|
Py_CLEAR(self->statement);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,8 +681,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
|
||||||
self->next_row = _pysqlite_fetch_one_row(self);
|
self->next_row = _pysqlite_fetch_one_row(self);
|
||||||
} else if (rc == SQLITE_DONE && !multiple) {
|
} else if (rc == SQLITE_DONE && !multiple) {
|
||||||
pysqlite_statement_reset(self->statement);
|
pysqlite_statement_reset(self->statement);
|
||||||
Py_DECREF(self->statement);
|
Py_CLEAR(self->statement);
|
||||||
self->statement = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (statement_type) {
|
switch (statement_type) {
|
||||||
|
@ -988,8 +987,7 @@ PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
|
||||||
|
|
||||||
if (self->statement) {
|
if (self->statement) {
|
||||||
(void)pysqlite_statement_reset(self->statement);
|
(void)pysqlite_statement_reset(self->statement);
|
||||||
Py_DECREF(self->statement);
|
Py_CLEAR(self->statement);
|
||||||
self->statement = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
|
Loading…
Reference in New Issue