[Bug analyzer/106283] RFE: analyzer handling of close_range and closefrom

"dmalcolm at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106283

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
         Depends on|                            |126830
   Last reconfirmed|                            |2026-08-13
     Ever confirmed|0                           |1

--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
$ cat t.c
#include <unistd.h>
#include <fcntl.h>

extern void closefrom(int lowfd);

void daemonize(void)
{
  int fd = open("/dev/null", O_RDWR);
  if (fd < 0)
    return;

  dup2(fd, 0);
  dup2(fd, 1);
  dup2(fd, 2);

  if (fd > 2)
    closefrom(3);  /* closes fd, but analyzer doesn't know */
}

$ gcc -fanalyzer -c t.c
t.c: In function 'daemonize':
t.c:18:1: warning: leak of file descriptor 'fd' [-Wanalyzer-fd-leak]

Trunk: https://godbolt.org/z/bGfn5n9Tz

Seen in the August 2026 OpenScanHub mass scan of Fedora 45 (PR 126830)
affecting audit, bash, and others (est. ~50-60 FPs).


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126830
[Bug 126830] Tracker bug for -fanalyzer false positives seen in August 2026
OpenScanHub mass scan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.