diff --git a/NEWS b/NEWS index 39af3a61..1c70c6da 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ What's new in psycopg 2.4.3 --------------------------- + - Fixed segfault in case of transaction started with connection lost + (and possibly other events). - Lazy import of the slow uuid module, thanks to Marko Kreen. diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index cee5ce4c..1f0d5da9 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -344,11 +344,13 @@ pq_execute_command_locked(connectionObject *conn, const char *query, } if (*pgres == NULL) { Dprintf("pq_execute_command_locked: PQexec returned NULL"); + PyEval_RestoreThread(*tstate); if (!PyErr_Occurred()) { const char *msg; msg = PQerrorMessage(conn->pgconn); if (msg && *msg) { *error = strdup(msg); } } + *tstate = PyEval_SaveThread(); goto cleanup; } @@ -635,11 +637,13 @@ pq_get_guc_locked( if (*pgres == NULL) { Dprintf("pq_get_guc_locked: PQexec returned NULL"); + PyEval_RestoreThread(*tstate); if (!PyErr_Occurred()) { const char *msg; msg = PQerrorMessage(conn->pgconn); if (msg && *msg) { *error = strdup(msg); } } + *tstate = PyEval_SaveThread(); goto cleanup; } if (PQresultStatus(*pgres) != PGRES_TUPLES_OK) {