Grab the GIL when checking for errors occurred

The problem was causing a segfault on BEGIN if the server is disconnected
after the connection is created.
This commit is contained in:
Daniele Varrazzo 2011-06-30 14:43:21 +01:00
parent d9fce1f837
commit de6f2ac387
2 changed files with 6 additions and 0 deletions

2
NEWS
View File

@ -1,6 +1,8 @@
What's new in psycopg 2.4.3 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. - Lazy import of the slow uuid module, thanks to Marko Kreen.

View File

@ -344,11 +344,13 @@ pq_execute_command_locked(connectionObject *conn, const char *query,
} }
if (*pgres == NULL) { if (*pgres == NULL) {
Dprintf("pq_execute_command_locked: PQexec returned NULL"); Dprintf("pq_execute_command_locked: PQexec returned NULL");
PyEval_RestoreThread(*tstate);
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
const char *msg; const char *msg;
msg = PQerrorMessage(conn->pgconn); msg = PQerrorMessage(conn->pgconn);
if (msg && *msg) { *error = strdup(msg); } if (msg && *msg) { *error = strdup(msg); }
} }
*tstate = PyEval_SaveThread();
goto cleanup; goto cleanup;
} }
@ -635,11 +637,13 @@ pq_get_guc_locked(
if (*pgres == NULL) { if (*pgres == NULL) {
Dprintf("pq_get_guc_locked: PQexec returned NULL"); Dprintf("pq_get_guc_locked: PQexec returned NULL");
PyEval_RestoreThread(*tstate);
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
const char *msg; const char *msg;
msg = PQerrorMessage(conn->pgconn); msg = PQerrorMessage(conn->pgconn);
if (msg && *msg) { *error = strdup(msg); } if (msg && *msg) { *error = strdup(msg); }
} }
*tstate = PyEval_SaveThread();
goto cleanup; goto cleanup;
} }
if (PQresultStatus(*pgres) != PGRES_TUPLES_OK) { if (PQresultStatus(*pgres) != PGRES_TUPLES_OK) {