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: Scanning devices from inside the kernel



Well after a string of kernel panics, I spotted the following comment above the declaration of IORegistryIterator::getNextObject():

"The entry returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it."

So be sure to remove the call to service->release() if you try out this code!

I am surprised to see that in the Darwin source there are examples of an object returned by an iterator being accessed after the iterator has been released. If the iterator only retains the object whilst it is pointing at it, surely the caller would need to retain the object before releasing the iterator? See IOPMPagingPlexus::setAggressiveness for an example.

Sam

On Friday, May 30, 2003, at 15:00 Australia/Melbourne, email@hidden wrote:

OSDictionary* services = IOService::serviceMatching(kIOMediaClass);
if (!services)
return;

OSIterator* iterator = IOService::getMatchingServices(services);
if (!iterator)
return;

while (true)
{
IOService* service = OSDynamicCast(IOService,
iterator->getNextObject());
if (!service)
break;

printf("name: %s\n", service->getName());
// service->release(); NO! - see IORegistryIterator::getNextObject()
}

iterator->release();
services->release();
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.



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.