From 396f1ed8dfbadda21c592bd49abdff671e03083c Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Thu, 21 Jul 2016 20:26:37 +0200 Subject: [PATCH] mshow: extract_mime: fix logic to not free filename pointing to auto var Found by clang-analyzer. --- mshow.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mshow.c b/mshow.c index 8cab666..48e4a2a 100644 --- a/mshow.c +++ b/mshow.c @@ -387,13 +387,16 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen) fwrite(body, 1, bodylen, stdout); } else { char buf[255]; - if (!filename) { + char *bufptr; + if (filename) { + bufptr = filename; + } else { snprintf(buf, sizeof buf, "attachment%d", mimecount); - filename = buf; + bufptr = buf; } - printf("%s\n", filename); - writefile(filename, body, bodylen); + printf("%s\n", bufptr); + writefile(bufptr, body, bodylen); } } else if (filename && strcmp(a, filename) == 0) { // extract by name