From 5a9246d6804ab8a6f2f23f3f4ace84a415140937 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 25 Aug 2012 11:19:39 -0700 Subject: Ensure inFile is always closed on error in cppit() Another instance of the can-return-in-rare-cases nature of LogFatal() raising red flags in static analysis. Resolves warning from Parfait 1.0.1: Error: File Leak File Leak: Leaked File inFile at line 1719 of imake.c in function 'cppit'. inFile initialized at line 1699 with fopen inFile leaks when inFile != NULL at line 1700 and fprintf(inFile, "%s\n", "/* imake - temporary file */") < 0 at line 1702. Signed-off-by: Alan Coopersmith --- imake.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/imake.c b/imake.c index 2ca34c3..a80e34a 100644 --- a/imake.c +++ b/imake.c @@ -1709,8 +1709,11 @@ cppit(const char *imakefile, const char *template, const char *masterc, fprintf(inFile, IncludeFmt, ImakeTmplSym) < 0 || optional_include(inFile, "IMAKE_ADMIN_MACROS", "adminmacros") || optional_include(inFile, "IMAKE_LOCAL_MACROS", "localmacros") || - fflush(inFile) || - fclose(inFile)) + fflush(inFile)) { + fclose(inFile); + LogFatal("Cannot write to %s.", masterc); + } + else if (fclose(inFile)) LogFatal("Cannot write to %s.", masterc); /* * Fork and exec cpp -- cgit v1.2.3