summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-10-10 11:47:28 +0000
committernicm <nicm@openbsd.org>2013-10-10 11:47:28 +0000
commit643c3daf92746ae7fb904cf9eac162db2ab8898b (patch)
tree3ffc132fc1bc33102552852f073af9acd98d6a4d
parentDon't add client formats when they are NULL. (diff)
downloadwireguard-openbsd-643c3daf92746ae7fb904cf9eac162db2ab8898b.tar.xz
wireguard-openbsd-643c3daf92746ae7fb904cf9eac162db2ab8898b.zip
Don't leak formats if they are added multiple times.
-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. */