pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix error handling in libpqrcv_connect()
Date: Tue, 24 Jan 2023 02:51:00 +0000
Message-ID: <E1pK9Ol-005Aeo-VA@gemulon.postgresql.org> (raw)

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_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c5864805ba99f79b49b12dc14499da58b0e15eb8

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(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1pK9Ol-005Aeo-VA@gemulon.postgresql.org>
Permalink:  ../E1pK9Ol-005Aeo-VA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pK9Ol-005Aeo-VA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Fix error handling in libpqrcv_connect()
  In-Reply-To: <E1pK9Ol-005Aeo-VA@gemulon.postgresql.org>
  References: <E1pK9Ol-005Aeo-VA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox