From abd799196873fe55ddad2e92a6d0ec1752fab8c3 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 3 Jan 2011 13:58:45 +0100 Subject: [PATCH] Fixed refcount bug with connection destroyed in a 2PC transaction --- psycopg/connection_type.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 15d943a2..97ca4e3c 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -305,8 +305,6 @@ _psyco_conn_tpc_finish(connectionObject *self, PyObject *args, goto exit; } } else { - PyObject *tmp; - /* committing/aborting our own transaction. */ if (!self->tpc_xid) { PyErr_SetString(ProgrammingError, @@ -332,11 +330,10 @@ _psyco_conn_tpc_finish(connectionObject *self, PyObject *args, goto exit; } + Py_CLEAR(self->tpc_xid); + /* connection goes ready */ self->status = CONN_STATUS_READY; - tmp = (PyObject *)self->tpc_xid; - self->tpc_xid = NULL; - Py_DECREF(tmp); } Py_INCREF(Py_None); @@ -912,6 +909,7 @@ connection_dealloc(PyObject* obj) if (self->encoding) free(self->encoding); if (self->critical) free(self->critical); + Py_CLEAR(self->tpc_xid); Py_CLEAR(self->async_cursor); Py_CLEAR(self->notice_list); Py_CLEAR(self->notice_filter); @@ -965,6 +963,7 @@ connection_repr(connectionObject *self) static int connection_traverse(connectionObject *self, visitproc visit, void *arg) { + Py_VISIT(self->tpc_xid); Py_VISIT(self->async_cursor); Py_VISIT(self->notice_list); Py_VISIT(self->notice_filter);