summaryrefslogtreecommitdiff
path: root/src/bin/psql/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r--src/bin/psql/common.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index fe8e049c4c1..4a50eb1e672 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1275,14 +1275,7 @@ sendquery_cleanup:
}
/* clean up after \bind */
- if (pset.bind_flag)
- {
- for (i = 0; i < pset.bind_nparams; i++)
- free(pset.bind_params[i]);
- free(pset.bind_params);
- pset.bind_params = NULL;
- pset.bind_flag = false;
- }
+ clean_bind_state();
/* reset \gset trigger */
if (pset.gset_prefix)
@@ -2253,6 +2246,26 @@ uri_prefix_length(const char *connstr)
}
/*
+ * Reset state related to \bind
+ *
+ * Clean up any state related to bind parameters and bind_flag. This needs
+ * to be called after processing a query or when running \bind.
+ */
+void
+clean_bind_state(void)
+{
+ if (pset.bind_flag)
+ {
+ for (int i = 0; i < pset.bind_nparams; i++)
+ free(pset.bind_params[i]);
+ free(pset.bind_params);
+ }
+
+ pset.bind_params = NULL;
+ pset.bind_flag = false;
+}
+
+/*
* Recognized connection string either starts with a valid URI prefix or
* contains a "=" in it.
*