aboutsummaryrefslogtreecommitdiff
path: root/status.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 /status.c
parent9642f0373f94d6015e66806c95ba1570c7bb06ea (diff)
downloadrtmux-65deba3a350f760dacdb170fbecfa07edf4e4711.tar.gz
rtmux-65deba3a350f760dacdb170fbecfa07edf4e4711.tar.bz2
rtmux-65deba3a350f760dacdb170fbecfa07edf4e4711.zip
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 'status.c')
-rw-r--r--status.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/status.c b/status.c
index 49215adf..32effe5d 100644
--- a/status.c
+++ b/status.c
@@ -468,6 +468,9 @@ status_message_set(struct client *c, const char *fmt, ...)
va_list ap;
int delay;
+ status_prompt_clear(c);
+ status_message_clear(c);
+
delay = options_get_number(&c->session->options, "display-time");
tv.tv_sec = delay / 1000;
tv.tv_usec = (delay % 1000) * 1000L;
@@ -493,7 +496,7 @@ status_message_clear(struct client *c)
c->message_string = NULL;
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
- c->flags |= CLIENT_STATUS;
+ c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */
screen_reinit(&c->status);
}
@@ -540,15 +543,20 @@ status_message_redraw(struct client *c)
}
void
-status_prompt_set(struct client *c,
- const char *msg, int (*fn)(void *, const char *), void *data, int flags)
+status_prompt_set(struct client *c, const char *msg,
+ int (*callbackfn)(void *, const char *), void (*freefn)(void *),
+ void *data, int flags)
{
+ status_message_clear(c);
+ status_prompt_clear(c);
+
c->prompt_string = xstrdup(msg);
c->prompt_buffer = xstrdup("");
c->prompt_index = 0;
- c->prompt_callback = fn;
+ c->prompt_callbackfn = callbackfn;
+ c->prompt_freefn = freefn;
c->prompt_data = data;
c->prompt_hindex = 0;
@@ -566,9 +574,12 @@ status_prompt_set(struct client *c,
void
status_prompt_clear(struct client *c)
{
- if (c->prompt_string == NULL)
+ if (c->prompt_string == NULL)
return;
+ if (c->prompt_freefn != NULL && c->prompt_data != NULL)
+ c->prompt_freefn(c->prompt_data);
+
mode_key_free(&c->prompt_mdata);
xfree(c->prompt_string);
@@ -580,7 +591,7 @@ status_prompt_clear(struct client *c)
c->prompt_buffer = NULL;
c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
- c->flags |= CLIENT_STATUS;
+ c->flags |= CLIENT_REDRAW; /* screen was frozen and may have changed */
screen_reinit(&c->status);
}
@@ -832,14 +843,14 @@ status_prompt_key(struct client *c, int key)
case MODEKEYCMD_CHOOSE:
if (*c->prompt_buffer != '\0') {
status_prompt_add_history(c);
- if (c->prompt_callback(
+ if (c->prompt_callbackfn(
c->prompt_data, c->prompt_buffer) == 0)
status_prompt_clear(c);
break;
}
/* FALLTHROUGH */
case MODEKEYCMD_QUIT:
- if (c->prompt_callback(c->prompt_data, NULL) == 0)
+ if (c->prompt_callbackfn(c->prompt_data, NULL) == 0)
status_prompt_clear(c);
break;
case MODEKEYCMD_OTHERKEY:
@@ -858,7 +869,7 @@ status_prompt_key(struct client *c, int key)
}
if (c->prompt_flags & PROMPT_SINGLE) {
- if (c->prompt_callback(
+ if (c->prompt_callbackfn(
c->prompt_data, c->prompt_buffer) == 0)
status_prompt_clear(c);
}