• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CFFileDescriptor fd leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFFileDescriptor fd leak?


  • Subject: Re: CFFileDescriptor fd leak?
  • From: Dave Keck <email@hidden>
  • Date: Thu, 20 Aug 2009 12:47:35 -1000

Hey,

I ran your test code and saw the same results. After tweaking the code a bit, I found that to have the kqueues cleaned up, you have to create a run loop source for the CFFD, add it to the run loop, and then remove it from the run loop. Here's the tweaked code:

==============================

#include <CoreFoundation/CoreFoundation.h>
#include <unistd.h>
#include <sys/event.h>

static void junkCallback(CFFileDescriptorRef fdref, CFOptionFlags callBackTypes, void *info) {}

int main(int argc, char *argv[])
{

    int i = 0;
    
    for (i = 0; i < 3; i++)
    {
    
        CFFileDescriptorRef fileDescriptor = nil;
        CFRunLoopSourceRef runLoopSource = nil;
        
        NSLog(@"CREATE %d", i);
        fileDescriptor = CFFileDescriptorCreate(NULL, 0, false, junkCallback, NULL);
        runLoopSource = CFFileDescriptorCreateRunLoopSource(NULL, fileDescriptor, 0);
        CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop], runLoopSource, kCFRunLoopDefaultMode);
        
        NSLog(@"DESTROY %d", i);
        CFRunLoopRemoveSource([[NSRunLoop currentRunLoop] getCFRunLoop], runLoopSource, kCFRunLoopDefaultMode);
        CFRelease(runLoopSource);
        CFFileDescriptorInvalidate(fileDescriptor);
        CFRelease(fileDescriptor);
    
    }
    
    sleep(-1);
    
    return 0;

}

==============================

I'd definitely consider your findings a bug. But I don't think it poses any real issue, since CFFileDescriptor is useless unless it's used with a run loop.

I'd say a radar is in order...

David
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: CFFileDescriptor fd leak?
      • From: "A.M." <email@hidden>
References: 
 >CFFileDescriptor fd leak? (From: "A.M." <email@hidden>)

  • Prev by Date: Re: CFFileDescriptor fd leak?
  • Next by Date: Re: which pages of the file are in the cache
  • Previous by thread: Re: CFFileDescriptor fd leak?
  • Next by thread: Re: CFFileDescriptor fd leak?
  • Index(es):
    • Date
    • Thread