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:
Darryl L. Miles 2025-02-13 08:22:43 +00:00 committed by Tim Edwards
parent e88dcba1c5
commit a60259ab63
1 changed files with 2 additions and 7 deletions

View File

@ -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;
}