Do not leak memory when working out job name in formats.
authornicm <nicm@openbsd.org>
Tue, 20 Feb 2018 10:43:46 +0000 (10:43 +0000)
committernicm <nicm@openbsd.org>
Tue, 20 Feb 2018 10:43:46 +0000 (10:43 +0000)
usr.bin/tmux/format.c

index c2b7f21..83ebb7b 100644 (file)
@@ -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) {