summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Paquier2024-09-19 06:39:01 +0000
committerMichael Paquier2024-09-19 06:39:01 +0000
commit87eeadaea1439693f6108ff599d750842ca6f338 (patch)
treeddb49231268ccfcceafb654eb40b83ff02513006 /src/test
parentd69a3f4d70b7cab328ba5d0944450d87f39c2eb4 (diff)
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
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/psql.out9
-rw-r--r--src/test/regress/sql/psql.sql5
2 files changed, 14 insertions, 0 deletions
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index 6aeb7cb9636..cf040fbd803 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -132,6 +132,15 @@ SELECT $1, $2 \parse stmt3
foo | bar
(1 row)
+-- Repeated calls. The second call generates an error, cleaning up the
+-- statement name set by the first call.
+\bind_named stmt4
+\bind_named
+\bind_named: missing required argument
+\g
+ERROR: there is no parameter $1
+LINE 1: SELECT $1, $2
+ ^
-- \close (extended query protocol)
\close
\close: missing required argument
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index 0a2f8b46922..8de90c805c0 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -58,6 +58,11 @@ SELECT $1, $2 \parse stmt3
\bind_named stmt1 \g
\bind_named stmt2 'foo' \g
\bind_named stmt3 'foo' 'bar' \g
+-- Repeated calls. The second call generates an error, cleaning up the
+-- statement name set by the first call.
+\bind_named stmt4
+\bind_named
+\g
-- \close (extended query protocol)
\close