pgsql: Fix error handling in libpqrcv_connect() - Mailing list pgsql-committers

From Andres Freund
Subject pgsql: Fix error handling in libpqrcv_connect()
Date
Msg-id E1pK9Om-005Aeu-01@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix error handling in libpqrcv_connect()

When libpqrcv_connect (also known as walrcv_connect()) failed, it leaked the
libpq connection. In most paths that's fairly harmless, as the calling process
will exit soon after. But e.g. CREATE SUBSCRIPTION could lead to a somewhat
longer lived leak.

Fix by releasing resources, including the libpq connection, on error.

Add a test exercising the error code path. To make it reliable and safe, the
test tries to connect to port=-1, which happens to fail during connection
establishment, rather than during connection string parsing.

Reviewed-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/20230121011237.q52apbvlarfv6jm6@awork3.anarazel.de
Backpatch: 11-

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/243373159fb427dfb6fcf43e2ac403d9d3b82752

Modified Files
--------------
.../libpqwalreceiver/libpqwalreceiver.c            | 26 +++++++++++++---------
src/test/regress/expected/subscription.out         | 10 ++++++++-
src/test/regress/sql/subscription.sql              |  9 +++++++-
3 files changed, 32 insertions(+), 13 deletions(-)


pgsql-committers by date:

Previous
From: David Rowley
Date:
Subject: pgsql: Use OFFSET 0 instead of ORDER BY to stop subquery pullup
Next
From: Andres Freund
Date:
Subject: pgsql: libpqwalreceiver: Convert to libpq-be-fe-helpers.h