[Python-checkins] r64930 - in python/trunk/Modules/_sqlite: connection.c cursor.c
alexandre.vassalotti
python-checkins at python.org
Sun Jul 13 23:47:59 CEST 2008
Author: alexandre.vassalotti
Date: Sun Jul 13 23:47:59 2008
New Revision: 64930
Log:
Issue #3153: sqlite leaks on error.
Changed statements of the form Py_DECREF(obj), obj = 0 to Py_CLEAR(obj).
Modified:
python/trunk/Modules/_sqlite/connection.c
python/trunk/Modules/_sqlite/cursor.c
Modified: python/trunk/Modules/_sqlite/connection.c
==============================================================================
--- python/trunk/Modules/_sqlite/connection.c (original)
+++ python/trunk/Modules/_sqlite/connection.c Sun Jul 13 23:47:59 2008
@@ -1014,19 +1014,16 @@
_pysqlite_seterror(self->db, NULL);
}
- Py_DECREF(statement);
- statement = 0;
+ Py_CLEAR(statement);
} else {
weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
if (!weakref) {
- Py_DECREF(statement);
- statement = 0;
+ Py_CLEAR(statement);
goto error;
}
if (PyList_Append(self->statements, weakref) != 0) {
- Py_DECREF(weakref);
- statement = 0;
+ Py_CLEAR(weakref);
goto error;
}
@@ -1050,15 +1047,13 @@
method = PyObject_GetAttrString(cursor, "execute");
if (!method) {
- Py_DECREF(cursor);
- cursor = 0;
+ Py_CLEAR(cursor);
goto error;
}
result = PyObject_CallObject(method, args);
if (!result) {
- Py_DECREF(cursor);
- cursor = 0;
+ Py_CLEAR(cursor);
}
error:
@@ -1081,15 +1076,13 @@
method = PyObject_GetAttrString(cursor, "executemany");
if (!method) {
- Py_DECREF(cursor);
- cursor = 0;
+ Py_CLEAR(cursor);
goto error;
}
result = PyObject_CallObject(method, args);
if (!result) {
- Py_DECREF(cursor);
- cursor = 0;
+ Py_CLEAR(cursor);
}
error:
@@ -1112,15 +1105,13 @@
method = PyObject_GetAttrString(cursor, "executescript");
if (!method) {
- Py_DECREF(cursor);
- cursor = 0;
+ Py_CLEAR(cursor);
goto error;
}
result = PyObject_CallObject(method, args);
if (!result) {
- Py_DECREF(cursor);
- cursor = 0;
+ Py_CLEAR(cursor);
}
error:
Modified: python/trunk/Modules/_sqlite/cursor.c
==============================================================================
--- python/trunk/Modules/_sqlite/cursor.c (original)
+++ python/trunk/Modules/_sqlite/cursor.c Sun Jul 13 23:47:59 2008
@@ -545,7 +545,7 @@
}
rc = pysqlite_statement_create(self->statement, self->connection, operation);
if (rc != SQLITE_OK) {
- self->statement = 0;
+ Py_CLEAR(self->statement);
goto error;
}
}
@@ -681,8 +681,7 @@
self->next_row = _pysqlite_fetch_one_row(self);
} else if (rc == SQLITE_DONE && !multiple) {
pysqlite_statement_reset(self->statement);
- Py_DECREF(self->statement);
- self->statement = 0;
+ Py_CLEAR(self->statement);
}
switch (statement_type) {
@@ -988,8 +987,7 @@
if (self->statement) {
(void)pysqlite_statement_reset(self->statement);
- Py_DECREF(self->statement);
- self->statement = 0;
+ Py_CLEAR(self->statement);
}
Py_INCREF(Py_None);
More information about the Python-checkins
mailing list