mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-12-01 05:03:44 +03:00
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:
parent
e24c3416e9
commit
2ad80da2f9
|
@ -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);
|
Dprintf("pq_execute: pg connection at %p OK", curs->conn->pgconn);
|
||||||
|
|
||||||
|
CLEARPGRES(curs->pgres);
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
pthread_mutex_lock(&(curs->conn->lock));
|
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) {
|
if (async == 0) {
|
||||||
CLEARPGRES(curs->pgres);
|
|
||||||
Dprintf("pq_execute: executing SYNC query: pgconn = %p", curs->conn->pgconn);
|
Dprintf("pq_execute: executing SYNC query: pgconn = %p", curs->conn->pgconn);
|
||||||
Dprintf(" %-.200s", query);
|
Dprintf(" %-.200s", query);
|
||||||
if (!psyco_green()) {
|
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("pq_execute: executing ASYNC query: pgconn = %p", curs->conn->pgconn);
|
||||||
Dprintf(" %-.200s", query);
|
Dprintf(" %-.200s", query);
|
||||||
|
|
||||||
CLEARPGRES(curs->pgres);
|
|
||||||
if (PQsendQuery(curs->conn->pgconn, query) == 0) {
|
if (PQsendQuery(curs->conn->pgconn, query) == 0) {
|
||||||
if (CONNECTION_BAD == PQstatus(curs->conn->pgconn)) {
|
if (CONNECTION_BAD == PQstatus(curs->conn->pgconn)) {
|
||||||
curs->conn->closed = 2;
|
curs->conn->closed = 2;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user