Mailing Lists: Apple Mailing Lists

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

IONotificationPortGetRunLoopSource, CFRunLoopAddSource, and CFRunLoopRemoveSource



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?

 _______________________________________________
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.