From: Daniele Varrazzo Date: Sat, 27 Aug 2022 20:29:56 +0000 (+0100) Subject: fix: use a "finally" to clear the result pointer after handling notifies X-Git-Tag: 3.1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=caa454b179eeab31d475b8939f350a1568f7242b;p=thirdparty%2Fpsycopg.git fix: use a "finally" to clear the result pointer after handling notifies The chance for this to fail failed is slim (an error in the logger? A ctrl-c just there?) but a bit of paranoia has never hurt anyone. --- diff --git a/psycopg/psycopg/pq/pq_ctypes.py b/psycopg/psycopg/pq/pq_ctypes.py index f01a0d231..a2c86dc40 100644 --- a/psycopg/psycopg/pq/pq_ctypes.py +++ b/psycopg/psycopg/pq/pq_ctypes.py @@ -56,8 +56,8 @@ def notice_receiver(arg: c_void_p, result_ptr: impl.PGresult_struct) -> None: pgconn.notice_handler(res) except Exception as exc: logger.exception("error in notice receiver: %s", exc) - - res._pgresult_ptr = None # avoid destroying the pgresult_ptr + finally: + res._pgresult_ptr = None # avoid destroying the pgresult_ptr class PGconn: diff --git a/psycopg_c/psycopg_c/pq/pgconn.pyx b/psycopg_c/psycopg_c/pq/pgconn.pyx index c96dd3b26..513e2f9f4 100644 --- a/psycopg_c/psycopg_c/pq/pgconn.pyx +++ b/psycopg_c/psycopg_c/pq/pgconn.pyx @@ -661,8 +661,8 @@ cdef void notice_receiver(void *arg, const libpq.PGresult *res_ptr) with gil: pgconn.notice_handler(res) except Exception as e: logger.exception("error in notice receiver: %s", e) - - res._pgresult_ptr = NULL # avoid destroying the pgresult_ptr + finally: + res._pgresult_ptr = NULL # avoid destroying the pgresult_ptr cdef (Py_ssize_t, libpq.Oid *, char * const*, int *, int *) _query_params_args(