summaryrefslogtreecommitdiffstats
path: root/cmd-command-prompt.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-07-17 09:26:21 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-07-17 09:26:21 +0000
commit441c118b6338a129b4690089e41948baceefb452 (patch)
tree88b35abd87d3fe7b1a79d722630145a95c49a721 /cmd-command-prompt.c
parentac555340553ab9ebbf4ccb3050150f589f5c2c46 (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
Diffstat (limited to 'cmd-command-prompt.c')
-rw-r--r--cmd-command-prompt.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index 7dd5a2b9..d59c51f7 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-command-prompt.c,v 1.18 2009-07-15 17:50:11 nicm Exp $ */
+/* $Id: cmd-command-prompt.c,v 1.19 2009-07-17 09:26:21 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,6 +31,7 @@ void cmd_command_prompt_init(struct cmd *, int);
int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
int cmd_command_prompt_callback(void *, const char *);
+void cmd_command_prompt_free(void *);
const struct cmd_entry cmd_command_prompt_entry = {
"command-prompt", NULL,
@@ -96,7 +97,8 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
cdata->template = NULL;
hdr = xstrdup(":");
}
- status_prompt_set(c, hdr, cmd_command_prompt_callback, cdata, 0);
+ status_prompt_set(c, hdr,
+ cmd_command_prompt_callback, cmd_command_prompt_free, cdata, 0);
xfree(hdr);
return (0);
@@ -112,10 +114,8 @@ cmd_command_prompt_callback(void *data, const char *s)
char *cause, *ptr, *buf, ch;
size_t len, slen;
- if (s == NULL) {
- xfree(cdata);
+ if (s == NULL)
return (0);
- }
slen = strlen(s);
len = 0;
@@ -139,12 +139,10 @@ cmd_command_prompt_callback(void *data, const char *s)
break;
}
}
- xfree(cdata->template);
buf[len] = '\0';
s = buf;
}
- xfree(cdata);
if (cmd_string_parse(s, &cmdlist, &cause) != 0) {
if (cause == NULL)
@@ -172,7 +170,17 @@ cmd_command_prompt_callback(void *data, const char *s)
cmd_list_exec(cmdlist, &ctx);
cmd_list_free(cmdlist);
- if (c->prompt_callback != (void *) &cmd_command_prompt_callback)
+ if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
return (1);
return (0);
}
+
+void
+cmd_command_prompt_free(void *data)
+{
+ struct cmd_command_prompt_data *cdata = data;
+
+ if (cdata->template != NULL)
+ xfree(cdata->template);
+ xfree(cdata);
+}