diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-02 13:15:00 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-01-22 11:12:36 +0000 |
commit | 2ad80da2f990d7f4ae099e25de3428598c8c0844 (patch) | |
tree | e057bec7307735a8b17cda55041524e960e722b8 | |
parent | e24c3416e9ce0b84e628915a916da4045507167d (diff) | |
download | psycopg2-2ad80da2f990d7f4ae099e25de3428598c8c0844.tar.gz |
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.
-rw-r--r-- | psycopg/pqpath.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 48c06ee..d22b725 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -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; |