From a49e188288682cfe2004ab5a5b9cd29f7335cb85 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Tue, 3 Apr 2018 08:54:53 -0700 Subject: [PATCH] clean: fix returning garbage in failure cases The variable contents was not being properly set when early failures happen in read_mom_contents. Found with clang static analyzer. --- src/clean.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clean.c b/src/clean.c index 29b95500..4d6facf6 100644 --- a/src/clean.c +++ b/src/clean.c @@ -226,6 +226,7 @@ static char *read_mom_contents(int version) return NULL; } + char *contents = NULL; int fd = fileno(f); if (fd == -1) { goto end; @@ -238,7 +239,7 @@ static char *read_mom_contents(int version) goto end; } - char *contents = malloc(stat.st_size + 1); + contents = malloc(stat.st_size + 1); if (!contents) { goto end; }