summaryrefslogtreecommitdiffstats
path: root/cmd-confirm-before.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-07-17 06:13:27 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-07-17 06:13:27 +0000
commit65deba3a350f760dacdb170fbecfa07edf4e4711 (patch)
treeaa04b471d50b4cc7417c15f5e88fa588c8eafa2b /cmd-confirm-before.c
parent9642f0373f94d6015e66806c95ba1570c7bb06ea (diff)
Memory could be leaked if a second prompt or message appeared while another was
still present, so add a separate prompt free callback and make the _clear function responsible for calling it if necessary (rather than the individual prompt callbacks). Also make both messages and prompts clear any existing when a new is set. In addition, the screen could be modified while the prompt is there, restore the redraw-entire-screen behaviour on prompt clear; add a comment as a reminder.
Diffstat (limited to 'cmd-confirm-before.c')
-rw-r--r--cmd-confirm-before.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index 2dbd72ce..c0fbe130 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -29,11 +29,7 @@ int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
void cmd_confirm_before_init(struct cmd *, int);
int cmd_confirm_before_callback(void *, const char *);
-
-struct cmd_confirm_before_data {
- struct client *c;
- char *cmd;
-};
+void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = {
"confirm-before", "confirm",
@@ -48,6 +44,11 @@ const struct cmd_entry cmd_confirm_before_entry = {
cmd_target_print
};
+struct cmd_confirm_before_data {
+ struct client *c;
+ char *cmd;
+};
+
void
cmd_confirm_before_init(struct cmd *self, int key)
{
@@ -91,8 +92,9 @@ cmd_confirm_before_exec(unused struct cmd *self, struct cmd_ctx *ctx)
cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(data->arg);
cdata->c = c;
- status_prompt_set(
- cdata->c, buf, cmd_confirm_before_callback, cdata, PROMPT_SINGLE);
+ status_prompt_set(cdata->c, buf,
+ cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
+ PROMPT_SINGLE);
xfree(buf);
return (1);
@@ -108,7 +110,7 @@ cmd_confirm_before_callback(void *data, const char *s)
char *cause;
if (s == NULL || tolower((u_char) s[0]) != 'y' || s[1] != '\0')
- goto out;
+ return (0);
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
if (cause != NULL) {
@@ -116,7 +118,7 @@ cmd_confirm_before_callback(void *data, const char *s)
status_message_set(c, "%s", cause);
xfree(cause);
}
- goto out;
+ return (0);
}
ctx.msgdata = NULL;
@@ -132,10 +134,15 @@ cmd_confirm_before_callback(void *data, const char *s)
cmd_list_exec(cmdlist, &ctx);
cmd_list_free(cmdlist);
-out:
+ return (0);
+}
+
+void
+cmd_confirm_before_free(void *data)
+{
+ struct cmd_confirm_before_data *cdata = data;
+
if (cdata->cmd != NULL)
xfree(cdata->cmd);
xfree(cdata);
-
- return (0);
}