This patch fixes some segfaults caused by performing certain operations on a closed connection object. The simplest example is: >>> import psycopg >>> conn = psycopg.connect('dbname=my_database') >>> conn.close() >>> conn.autocommit() The patch adds checks to the set_isolation_level(), autocommit() and serialize() methods to see if the connection is closed, and cleans up some dangling pointers during the connection close process to make future problems easier to debug. -- James Henstridge (2005-03-23) --- psycopg-1.1.18/connection.c.orig 2005-03-23 18:02:14.763628280 +0800 +++ psycopg-1.1.18/connection.c 2005-03-23 18:04:04.849892624 +0800 @@ -265,12 +265,15 @@ _psyco_conn_close(connobject *self) Py_DECREF(self->cursors); Py_DECREF(self->avail_conn); + self->cursors = NULL; + self->avail_conn = NULL; /* orphan default cursor and destroy it (closing the last connection to the database) */ Dprintf("_psyco_conn_close(): killing stdmanager\n"); self->stdmanager->conn = NULL; Py_DECREF(self->stdmanager); + self->stdmanager = NULL; } static PyObject * @@ -460,7 +463,9 @@ psyco_conn_set_isolation_level(connobjec if (!PyArg_ParseTuple(args, "l", &level)) { return NULL; } - + + EXC_IFCLOSED(self); + _psyco_conn_set_isolation_level(self, level); Py_INCREF(Py_None); @@ -484,6 +489,9 @@ psyco_conn_autocommit(connobject *self, } if (ac == 0) isolation_level = 2; + + EXC_IFCLOSED(self); + _psyco_conn_set_isolation_level(self, isolation_level); Py_INCREF(Py_None); @@ -504,6 +512,8 @@ psyco_conn_serialize(connobject *self, P return NULL; } + EXC_IFCLOSED(self); + /* save the value */ self->serialize = (int)se;