libc_r kqueue fd leak

Ed Maste emaste at
Tue May 24 14:51:54 PDT 2005

On Tue, May 24, 2005 at 01:36:48PM -0400, Ed Maste wrote:

> On Tue, May 24, 2005 at 12:59:07PM -0400, Ed Maste wrote:
> > We discovered a kqueue leak when running one of our 4.x applications on
> > FreeBSD 5.3 using the compat libc_r.  It turns out it's caused by libc_r's
> > close() failing.
> I've attached a patch which stops libc_r close() from bailing if fstat()
> returns an error.  This fixes the kqueue leak.  This logic would also have
> to make its way into the compat library via 4.x to fully resolve the issue.

After a little more research it seems the kernel fix is already documented
in threads/75795.  Version 1.77 of kern_event.c changed kqueue_stat to just
return ENXIO.

We discovered the problem because each call in our app to getipnodebyname
(and in turn the resolver) leaked one kqueue, which eventually used up all
kernel memory and then caused a panic.

I noticed that jmg originally did the kqueue locking work which removed
kqueue_stat, hence the CC:.


Ed Maste, Sandvine Incorporated

More information about the freebsd-stable mailing list