From fb46667d07def5942735f08e5a6c006ce794fbc0 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 17 Jul 2009 06:13:28 +0000 Subject: 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. --- usr.bin/tmux/status.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'usr.bin/tmux/status.c') diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 107a73a64fb..ca9bbd482ae 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.11 2009/07/16 23:25:21 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.12 2009/07/17 06:13:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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); } -- cgit v1.2.3