From 85fdc828e7c32e981c4b586aa17dee6dcc1e14c4 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Mon, 20 Apr 2009 20:19:55 +0200 Subject: [PATCH] Fix to double free segfault in cursor --- ChangeLog | 4 ++++ psycopg/cursor_type.c | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4d6086b..a18cf42e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-04-19 Federico Di Gregorio + * 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. diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 586de895..d4f0baa4 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -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); }