pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: psql: Clean up more aggressively state of \bind[_named], \parse
Date: Thu, 19 Sep 2024 06:39:18 +0000
Message-ID: <E1srAow-001kLE-7L@gemulon.postgresql.org> (raw)

psql: Clean up more aggressively state of \bind[_named], \parse and \close

This fixes a couple of issues with the psql meta-commands mentioned
above when called repeatedly:
- The statement name is reset for each call.  If a command errors out,
its send_mode would still be set, causing an incorrect path to be taken
when processing a query.  For \bind_named, this could trigger an
assertion failure as a statement name is always expected for this
meta-command.  This issue has been introduced by d55322b0da60.
- The memory allocated for bind parameters can be leaked.  This is a bug
enlarged by d55322b0da60 that exists since 5b66de3433e2, as it is also
possible to leak memory with \bind in v16 and v17.  This requires a fix
that will be done on the affected branches separately.  This issue is
taken care of here for HEAD.

This patch tightens the cleanup of the state used for the extended
protocol meta-commands (bind parameters, send mode, statement name) by
doing it before running each meta-command on top of doing it once a
query has been processed, avoiding any leaks and the inconsistencies
when mixing calls, by refactoring the cleanup in a single routine used
in all the code paths where this step is required.

Reported-by: Alexander Lakhin
Author: Anthonin Bonnefoy
Discussion: https://postgr.es/m/2e5b89af-a351-ff0a-000c-037ac28314ab@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/87eeadaea1439693f6108ff599d750842ca6f338

Modified Files
--------------
src/bin/psql/command.c             | 12 ++++----
src/bin/psql/common.c              | 59 ++++++++++++++++++++++++--------------
src/bin/psql/common.h              |  1 +
src/test/regress/expected/psql.out |  9 ++++++
src/test/regress/sql/psql.sql      |  5 ++++
5 files changed, 59 insertions(+), 27 deletions(-)



Message-ID: <E1srAow-001kLE-7L@gemulon.postgresql.org>
Permalink:  ../E1srAow-001kLE-7L@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1srAow-001kLE-7L@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: psql: Clean up more aggressively state of \bind[_named], \parse
  In-Reply-To: <E1srAow-001kLE-7L@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