]> git.ipfire.org Git - thirdparty/postgresql.git/commit
psql: Clean up more aggressively state of \bind[_named], \parse and \close
authorMichael Paquier <michael@paquier.xyz>
Thu, 19 Sep 2024 06:39:01 +0000 (15:39 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 19 Sep 2024 06:39:01 +0000 (15:39 +0900)
commit87eeadaea1439693f6108ff599d750842ca6f338
treeddb49231268ccfcceafb654eb40b83ff02513006
parentd69a3f4d70b7cab328ba5d0944450d87f39c2eb4
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
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/common.h
src/test/regress/expected/psql.out
src/test/regress/sql/psql.sql