Don't call CLEARPGRES on the cursor state without holding the gil

There is a chance it is executed by two different threads resulting in
issue #384.

I havent't found any other case that may lead to double free.
This commit is contained in:
Daniele Varrazzo 2019-01-02 13:15:00 +01:00
parent e24c3416e9
commit 2ad80da2f9

View File

@ -971,6 +971,8 @@ pq_execute(cursorObject *curs, const char *query, int async, int no_result, int
}
Dprintf("pq_execute: pg connection at %p OK", curs->conn->pgconn);
CLEARPGRES(curs->pgres);
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&(curs->conn->lock));
@ -982,7 +984,6 @@ pq_execute(cursorObject *curs, const char *query, int async, int no_result, int
}
if (async == 0) {
CLEARPGRES(curs->pgres);
Dprintf("pq_execute: executing SYNC query: pgconn = %p", curs->conn->pgconn);
Dprintf(" %-.200s", query);
if (!psyco_green()) {
@ -1024,7 +1025,6 @@ pq_execute(cursorObject *curs, const char *query, int async, int no_result, int
Dprintf("pq_execute: executing ASYNC query: pgconn = %p", curs->conn->pgconn);
Dprintf(" %-.200s", query);
CLEARPGRES(curs->pgres);
if (PQsendQuery(curs->conn->pgconn, query) == 0) {
if (CONNECTION_BAD == PQstatus(curs->conn->pgconn)) {
curs->conn->closed = 2;