From b9d27b0dbc428e504c36ffa2e1ef66beffd7cd66 Mon Sep 17 00:00:00 2001 From: zcl Date: Wed, 25 Sep 2024 17:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3python3.9=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=8C=82=E6=8E=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- psycopg/connection_type.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index d3eb601..358acfe 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -1356,8 +1356,8 @@ register_type_uint(connectionObject *self, PyThreadState **tstate) } if (typecast_add((PyObject *)obj, self->string_types, 0) < 0) { goto end; } rv = 0; - free(_typecast_INTEGER_types); end: + free(_typecast_INTEGER_types); Py_XDECREF(values); Py_XDECREF(name); return rv; @@ -1428,14 +1428,25 @@ connection_setup(connectionObject *self, const char *dsn, long int async) Dprintf("connection_setup: good connection object at %p, refcnt = " FORMAT_CODE_PY_SSIZE_T, self, Py_REFCNT(self)); + PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState)); Py_BEGIN_ALLOW_THREADS; pthread_mutex_lock(&self->lock); sql_compatibility_value = pq_get_guc_locked(self, "sql_compatibility", &_save); set_sql_compatibility(self, sql_compatibility_value); - if (register_type_uint(self, &_save)) { goto exit; } + memcpy(tstate, _save, sizeof(_save)); pthread_mutex_unlock(&self->lock); Py_END_ALLOW_THREADS; + + pthread_mutex_lock(&self->lock); + if (register_type_uint(self, &tstate)) { + goto exit; + } + if (tstate) { + free(tstate); + tstate = NULL; + } + pthread_mutex_unlock(&self->lock); exit: if (sql_compatibility_value){