Fix to double free segfault in cursor

This commit is contained in:
Federico Di Gregorio 2009-04-20 20:19:55 +02:00
parent 5db66038fe
commit 85fdc828e7
2 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,9 @@
2009-04-19 Federico Di Gregorio <fog@initd.org>
* psycopg/cursor_type.c: patch from Gangadharan to avoid double
free of the cursor when the connection that creates it is closed
implicitly by dealloc.
* psycopg/connection_type.c: patch from Gangadharan to avoid double
free of the connection object when calling close() implicitly.

View File

@ -1661,7 +1661,7 @@ static int
cursor_setup(cursorObject *self, connectionObject *conn, const char *name)
{
Dprintf("cursor_setup: init cursor object at %p", self);
Dprintf("cursor_setup: parameters: name = %s, conn = %p", name, conn);
Dprintf("cursor_setup: parameters: name = %s, conn = %p", name, conn);
if (name) {
self->name = PyMem_Malloc(strlen(name)+1);
@ -1717,6 +1717,8 @@ static void
cursor_dealloc(PyObject* obj)
{
cursorObject *self = (cursorObject *)obj;
PyObject_GC_UnTrack(self);
if (self->name) PyMem_Free(self->name);
@ -1734,8 +1736,7 @@ cursor_dealloc(PyObject* obj)
Dprintf("cursor_dealloc: deleted cursor object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj, obj->ob_refcnt);
obj->ob_type->tp_free(obj);
}