From a60259ab6387125e73d049f153ddc8263f478794 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Thu, 13 Feb 2025 08:22:43 +0000 Subject: [PATCH] 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. --- utils/path.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/utils/path.c b/utils/path.c index e42f96d0..accd41d6 100644 --- a/utils/path.c +++ b/utils/path.c @@ -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; }