From ab6f0bb3485f6626bad6f585e4d17059fe4f7152 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 20 Feb 2018 10:43:46 +0000 Subject: [PATCH] Do not leak memory when working out job name in formats. --- format.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index be53ad93..0cd3503c 100644 --- a/format.c +++ b/format.c @@ -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) {