summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-02-16 18:43:07 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-02-16 18:43:07 +0000
commita766f9743aa2bd9ed7caf5a97ea64f4bc2758ba1 (patch)
tree450ecae1efabd05941245ef3049598088b52bf33
parent17017ef3bcb433355fbfbdf479edfa9b7c4d13b1 (diff)
Don't leak existing keys.
-rw-r--r--tty-keys.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/tty-keys.c b/tty-keys.c
index 062be838..6f56b15c 100644
--- a/tty-keys.c
+++ b/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);