mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-08-22 14:17:43 +02:00
CodeQL File{MayNot,Never}BeClosed.ql file-handle resource leaks
Guided by CodeQL static code analyser. FileMayNotBeClosed.ql FileMayNeverBeClosed.ql The trick with "if(fp != stdout)" is problematic (to analyser) as technically 'stdout' can be a global pointer that COULD be modified any time, so it might have changed between the fopen() and fclose() calls so the close MAY NEVER occurs (which is problem the analyzer can see). So local state is maintained as a bool which will also clarify to the compiler see the intention without concern for external stdout modification. Some items appear to be out and out leaks when certain commands are use.
This commit is contained in:
committed by
Tim Edwards
parent
7960020f7c
commit
e88dcba1c5
+7
-3
@@ -122,7 +122,6 @@ char *path; /* a search path */
|
||||
char *libPath; /* a library search path */
|
||||
|
||||
{
|
||||
FILE *f;
|
||||
int max, red, green, blue, newmax, argc, i;
|
||||
colorEntry *ce;
|
||||
char fullName[256], inputLine[128], colorName[100];
|
||||
@@ -135,7 +134,7 @@ char *libPath; /* a library search path */
|
||||
(void) sprintf(fullName, "%.80s.%.80s.%.80s", techStyle,
|
||||
dispType, monType);
|
||||
|
||||
f = PaOpen(fullName, "r", ".cmap", path, libPath, (char **) NULL);
|
||||
FILE *f = PaOpen(fullName, "r", ".cmap", path, libPath, (char **) NULL);
|
||||
if (f == NULL)
|
||||
{
|
||||
/* Check for original ".cmap1" file (prior to magic v. 7.2.27) */
|
||||
@@ -163,7 +162,7 @@ char *libPath; /* a library search path */
|
||||
|
||||
TxError("Syntax error in color map file \"%s.cmap\"\n", fullName);
|
||||
TxError("Last color read was index %d\n", max);
|
||||
return FALSE;
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -219,6 +218,11 @@ char *libPath; /* a library search path */
|
||||
|
||||
GrSetCMap();
|
||||
return TRUE;
|
||||
|
||||
cleanup:
|
||||
if(f)
|
||||
fclose(f);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user