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:
parent
e88dcba1c5
commit
a60259ab63
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue