diff --git a/psycopg/cursor_int.c b/psycopg/cursor_int.c index a4acba1f..653071c1 100644 --- a/psycopg/cursor_int.c +++ b/psycopg/cursor_int.c @@ -74,6 +74,7 @@ curs_get_last_result(cursorObject *self) { IFCLEARPGRES(self->pgres); self->pgres = pgres; } + Py_XDECREF(self->conn->async_cursor); self->conn->async_cursor = NULL; pthread_mutex_unlock(&(self->conn->lock)); Py_END_ALLOW_THREADS; diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 14710a65..b987164c 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -299,6 +299,7 @@ pq_clear_async(connectionObject *conn) Dprintf("pq_clear_async: clearing PGresult at %p", pgres); CLEARPGRES(pgres); } + Py_XDECREF(conn->async_cursor); conn->async_cursor = NULL; } @@ -746,6 +747,7 @@ pq_execute(cursorObject *curs, const char *query, int async) } else { curs->conn->async_status = async_status; + Py_INCREF(curs); curs->conn->async_cursor = (PyObject*)curs; }