summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2018-02-20 10:43:47 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2018-02-20 10:43:47 +0000
commit9e4ef6b719132193bf380e12e17be5c45cea99a0 (patch)
tree8319be00405675f84242ee102649e9f0d3739607 /usr.bin/tmux
parentd03e62a7b62303ef650eed58e033ff97a977e3b9 (diff)
Do not leak memory when working out job name in formats.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/format.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index c2b7f215fcc..83ebb7b1f21 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.151 2018/01/18 14:28:11 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.152 2018/02/20 10:43:46 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1121,7 +1121,7 @@ format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
char *
format_expand(struct format_tree *ft, const char *fmt)
{
- char *buf, *out;
+ char *buf, *out, *name;
const char *ptr, *s, *saved = fmt;
size_t off, len, n, outlen;
int ch, brackets;
@@ -1160,8 +1160,11 @@ format_expand(struct format_tree *ft, const char *fmt)
if (ft->flags & FORMAT_NOJOBS)
out = xstrdup("");
- else
- out = format_job_get(ft, xstrndup(fmt, n));
+ else {
+ name = xstrndup(fmt, n);
+ out = format_job_get(ft, name);
+ free(name);
+ }
outlen = strlen(out);
while (len - off < outlen + 1) {