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-22 21:02:49 -05:00
committed by Tim Edwards
parent e88dcba1c5
commit a60259ab63
+2 -7
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;
}