Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: IONotificationPortGetRunLoopSource, CFRunLoopAddSource, and CFRunLoopRemoveSource



Done. Radar 3822301. Thank you for checking.

> ----------
> From: 	Chris Sarcone
> Sent: 	Thursday, September 30, 2004 10:57 AM
> To: 	Joe van Tunen
> Cc: 	email@hidden
> Subject: 	Re: IONotificationPortGetRunLoopSource, CFRunLoopAddSource, and CFRunLoopRemoveSource
> 
> Joe --
> 
> > I am following the steps in the "Passing Untyped Data Asynchronously"  
> > "Application Procedure Using CFRunLoop" section of the "Writing a  
> > Custom User Client" documentation at
> > http://developer.apple.com/documentation/DeviceDrivers/Conceptual/ 
> > WritingDeviceDriver/MakingHWAccessible/chapter_5_section_3.html
> >
> > but I have run into a minor problem. I have setup code based on the  
> > documentation that looks like this:
> >
> > 	kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
> > 	appRunLoop = CFRunLoopGetCurrent();
> > 	CFRetain( appRunLoop );
> > 	notificationPortRef = IONotificationPortCreate( masterPort );
> > 	notificationRunLoopSource = IONotificationPortGetRunLoopSource(  
> > notificationPortRef );
> > 	CFRunLoopAddSource( appRunLoop, notificationRunLoopSource,  
> > kCFRunLoopDefaultMode );
> > 	notificationMachPort = IONotificationPortGetMachPort(  
> > notificationPortRef );
> > 	kernResult = IOConnectSetNotificationPort( userClient, 0,  
> > notificationMachPort, 0 );
> > and cleanup code that looks like this (the real code checks function  
> > results):
> >
> > 	CFRunLoopRemoveSource( appRunLoop, notificationRunLoopSource,  
> > kCFRunLoopDefaultMode );
> > 	CFRelease( notificationRunLoopSource );
> > 	IONotificationPortDestroy( notificationPortRef );
> > 	CFRelease( appRunLoop );
> >
> > The application crashes when IONotificationPortDestroy is called  
> > (using OS X 10.3.5):
> >
> > 0   libobjc.A.dylib                	0x908311f4 objc_msgSend + 0x14
> > 1   com.apple.CoreFoundation       	0x901d8714 __CFMachPortDeallocate  
> > + 0x2c
> > 2   com.apple.CoreFoundation       	0x90190cf8 CFRelease + 0x1e8
> > 3   com.apple.CoreFoundation       	0x90190cf8 CFRelease + 0x1e8
> > 4   com.apple.framework.IOKit      	0x9058d70c  
> > IONotificationPortDestroy + 0x2c
> > If I remove the "CFRelease( notificationRunLoopSource )" line, the  
> > crash does not occur. The documentation says "Obtain a run-loop source  
> > object from the notification-port object. Call the  
> > IONotificationPortGetRunLoopSource function, passing in the  
> > IONotificationPortRef object. This call returns a CFRunLoopSourceRef  
> > object." and "Release the CFRunLoopSourceRef object by calling  
> > CFRelease on it." Is the documentation wrong and the CFRelease should  
> > not be there, or is there something else wrong with my code? Maybe a  
> > CFRetain should be added but I don't think that would be necessary  
> > because CFRunLoopAddSource should do that, shouldn't it?
> 
> If you look at the source for the IOKitUser project in Darwin, you'll  
> see that IONotificationPortDestroy() checks to see if the runloop  
> source is NULL or not and will call CFRelease() on it. Since you called  
> IONotificationPortGetRunLoopSource(), not  
> IONotificationPortCreateRunLoopSource() or  
> IONotificationPortCopyRunLoopSource(), I don't think you're supposed to  
> release it (and the documentation is incorrect). Please file a bug  
> against the documentation.
> 
> Thanks,
> 
> -- Chris
> 
> ------------------
> 6 Infinite Loop
> M/S 306-2MS
> Cupertino CA 95014
> phone: (408) 974-4033
> fax:   (408) 862-7577
> email: email@hidden
> 
> 
> 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-drivers/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.