summaryrefslogtreecommitdiff
path: root/src/bin/scripts/dropuser.c
diff options
context:
space:
mode:
authorTom Lane2016-08-30 21:02:02 +0000
committerTom Lane2016-08-30 21:02:02 +0000
commit9daec77e165de461fca9d5bc3ece86a91aba5804 (patch)
tree0d5fc873a9602824e8363548b71af20b01f565c5 /src/bin/scripts/dropuser.c
parent37f6fd1eaab698983ca1fb2a036d52381347ac71 (diff)
Simplify correct use of simple_prompt().
The previous API for this function had it returning a malloc'd string. That meant that callers had to check for NULL return, which few of them were doing, and it also meant that callers had to remember to free() the string later, which required extra logic in most cases. Instead, make simple_prompt() write into a buffer supplied by the caller. Anywhere that the maximum required input length is reasonably small, which is almost all of the callers, we can just use a local or static array as the buffer instead of dealing with malloc/free. A fair number of callers used "pointer == NULL" as a proxy for "haven't requested the password yet". Maintaining the same behavior requires adding a separate boolean flag for that, which adds back some of the complexity we save by removing free()s. Nonetheless, this nets out at a small reduction in overall code size, and considerably less code than we would have had if we'd added the missing NULL-return checks everywhere they were needed. In passing, clean up the API comment for simple_prompt() and get rid of a very-unnecessary malloc/free in its Windows code path. This is nominally a bug fix, but it does not seem worth back-patching, because the actual risk of an OOM failure in any of these places seems pretty tiny, and all of them are client-side not server-side anyway. This patch is by me, but it owes a great deal to Michael Paquier who identified the problem and drafted a patch for fixing it the other way. Discussion: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com>
Diffstat (limited to 'src/bin/scripts/dropuser.c')
-rw-r--r--src/bin/scripts/dropuser.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c
index 31fa28f7cdc..ebcc15209c3 100644
--- a/src/bin/scripts/dropuser.c
+++ b/src/bin/scripts/dropuser.c
@@ -46,6 +46,7 @@ main(int argc, char *argv[])
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool interactive = false;
+ char dropuser_buf[128];
PQExpBufferData sql;
@@ -108,7 +109,11 @@ main(int argc, char *argv[])
if (dropuser == NULL)
{
if (interactive)
- dropuser = simple_prompt("Enter name of role to drop: ", 128, true);
+ {
+ simple_prompt("Enter name of role to drop: ",
+ dropuser_buf, sizeof(dropuser_buf), true);
+ dropuser = dropuser_buf;
+ }
else
{
fprintf(stderr, _("%s: missing required argument role name\n"), progname);