mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-27 02:23:15 +01:00
Don't leak existing keys.
This commit is contained in:
parent
17017ef3bc
commit
a766f9743a
19
tty-keys.c
19
tty-keys.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tty-keys.c,v 1.21 2009-01-28 19:52:21 nicm Exp $ */
|
||||
/* $Id: tty-keys.c,v 1.22 2009-02-16 18:43:07 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -123,7 +123,14 @@ tty_keys_cmp(struct tty_key *k1, struct tty_key *k2)
|
||||
void
|
||||
tty_keys_add(struct tty *tty, const char *s, int key, int flags)
|
||||
{
|
||||
struct tty_key *tk;
|
||||
struct tty_key *tk, tl;
|
||||
|
||||
tl.string = s;
|
||||
if ((tk = RB_FIND(tty_keys, &tty->ktree, &tl)) != NULL) {
|
||||
log_debug("already key matching: %s (old %x, new %x)",
|
||||
tk->string, tk->key, key);
|
||||
return;
|
||||
}
|
||||
|
||||
tk = xmalloc(sizeof *tk);
|
||||
tk->string = xstrdup(s);
|
||||
@ -174,10 +181,10 @@ tty_keys_init(struct tty *tty)
|
||||
void
|
||||
tty_keys_free(struct tty *tty)
|
||||
{
|
||||
struct tty_key *tk, *tl;
|
||||
|
||||
for (tk = RB_MIN(tty_keys, &tty->ktree); tk != NULL; tk = tl) {
|
||||
tl = RB_NEXT(tty_keys, &tty->ktree, tk);
|
||||
struct tty_key *tk;
|
||||
|
||||
while (!RB_EMPTY(&tty->ktree)) {
|
||||
tk = RB_ROOT(&tty->ktree);
|
||||
RB_REMOVE(tty_keys, &tty->ktree, tk);
|
||||
xfree(tk->string);
|
||||
xfree(tk);
|
||||
|
Loading…
Reference in New Issue
Block a user