https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125119
Bug ID: 125119
Summary: socket fd leak detection fails to track close() when
the fd is stored via a linked list pointer dereference
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: daniel.lovasko at gmail dot com
Target Milestone: ---
#include <sys/socket.h>
#include <stdbool.h>
#include <unistd.h>
struct node {
int fd;
struct node *next;
};
static struct node *list;
static bool create_fds(void)
{
for (struct node *n = list; n != NULL; n = n->next) {
n->fd = socket(AF_INET, SOCK_DGRAM, 0);
if (n->fd == -1)
return false;
if (bind(n->fd, (void*)0, 0) == -1) {
close(n->fd); /* <-- analyzer doesn't see this */
return false;
}
}
return true;
}