FSEvents API leaks file descriptors (KQUEUE)

367 views Asked by At

I'm trying to monitor a set of paths with the FSEvents API (OSX 10.9, ARC enabled, sandboxed). The following code leaks file descriptors. Using lsof, I get a lot of:

Project 70505 aaa   22u  KQUEUE                  count=0, state=0x1

After a couple of hours, I hit the max open descriptors limit and FSEventStreamCreate start failing.

Any idea why it's leaking two file descriptors every time I run this ?

FSEventStreamContext callbackInfo;

callbackInfo.version = 0;
callbackInfo.info    = NULL;
callbackInfo.retain  = NULL;
callbackInfo.release = NULL;
callbackInfo.copyDescription = NULL;

// ===== +2 descriptors ======
FSEventStreamRef ev = FSEventStreamCreate(NULL,
                                              NULL,
                                              &callbackInfo,
                                              ((__bridge CFArrayRef)[NSArray arrayWithObject:@"/Users/aaa/Downloads"]),
                                              kFSEventStreamEventIdSinceNow,
                                              0,
                                              kFSEventStreamCreateFlagUseCFTypes | kFSEventStreamCreateFlagWatchRoot);
// ===== +2 descriptors ======
FSEventStreamScheduleWithRunLoop(ev, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

FSEventStreamStart(ev);
FSEventStreamStop(ev);

FSEventStreamUnscheduleFromRunLoop(ev, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
// ===== -1 descriptor ======
FSEventStreamInvalidate(ev);
FSEventStreamRelease(ev);
0

There are 0 answers