#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <assert.h>
int main() {
int iters = 0;
for (;;) {
int dirfd = open(".", O_DIRECTORY);
assert(dirfd > 0);
int fd = openat(dirfd, "test.c", O_RDONLY);
if (fd < 0) {
break;
} else {
close(fd);
close(dirfd);
}
++iters;
}
printf("iters = %d, errno = %d\n", iters, errno);
return 0;
}
but it fails and the output is iters = 123, errno = 12, because the function at_kfd (in syscall.c) calls file_get, but does not call file_decref before returning.
The following program (
test.c
) should never exit:but it fails and the output is
iters = 123, errno = 12
, because the functionat_kfd
(insyscall.c
) callsfile_get
, but does not callfile_decref
before returning.