summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/format.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 3c45fa1515e..0a5ef54c483 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.27 2013/10/10 11:47:11 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.28 2013/10/10 11:47:28 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -151,6 +151,7 @@ void
format_add(struct format_tree *ft, const char *key, const char *fmt, ...)
{
struct format_entry *fe;
+ struct format_entry *fe_now;
va_list ap;
fe = xmalloc(sizeof *fe);
@@ -160,7 +161,13 @@ format_add(struct format_tree *ft, const char *key, const char *fmt, ...)
xvasprintf(&fe->value, fmt, ap);
va_end(ap);
- RB_INSERT(format_tree, ft, fe);
+ fe_now = RB_INSERT(format_tree, ft, fe);
+ if (fe_now != NULL) {
+ free(fe_now->value);
+ fe_now->value = fe->value;
+ free(fe->key);
+ free(fe);
+ }
}
/* Find a format entry. */