[PATCH:imake 2/2] Ensure inFile is always closed on error in cppit()

Alan Coopersmith alan.coopersmith at oracle.com
Sat Aug 25 11:37:46 PDT 2012


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 <alan.coopersmith at oracle.com>
---
 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
-- 
1.7.9.2



More information about the xorg-devel mailing list