diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-08-25 11:19:39 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-08-25 11:23:01 -0700 |
commit | 5a9246d6804ab8a6f2f23f3f4ace84a415140937 (patch) | |
tree | aa8cf08d97714e456621b0dc6517b9b949140154 | |
parent | 464ba911c3b84abb0140e9f66756d1cc887f78ad (diff) |
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 <alan.coopersmith@oracle.com>
-rw-r--r-- | imake.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 |