aboutsummaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
Diffstat (limited to 'format.c')
-rw-r--r--format.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/format.c b/format.c
index 16ac53d6..2275090e 100644
--- a/format.c
+++ b/format.c
@@ -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. */