mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-10-06 09:53:00 +02:00
CodeQL FileMayNotBeClosed.ql PaCheckCompressed() apparently leaks an 'fd'
CodeQL complains of a _potential_ leak (I can't see it), seems false positive but also a clear case to use POSIX access(R_OK) instead.
This commit is contained in:
committed by
Tim Edwards
parent
e88dcba1c5
commit
a60259ab63
+2
-7
@@ -82,19 +82,14 @@ char *
|
||||
PaCheckCompressed(filename)
|
||||
const char *filename;
|
||||
{
|
||||
int fd;
|
||||
char *gzname;
|
||||
|
||||
gzname = (char *)mallocMagic(strlen(filename) + 4);
|
||||
sprintf(gzname, "%s.gz", filename);
|
||||
|
||||
fd = open(gzname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
int err = access(gzname, R_OK);
|
||||
if (err < 0)
|
||||
strcpy(gzname, filename); /* always shorter than allocation */
|
||||
}
|
||||
else
|
||||
close(fd);
|
||||
|
||||
return gzname;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user