Re: Scanning devices from inside the kernel
Re: Scanning devices from inside the kernel
- Subject: Re: Scanning devices from inside the kernel
- From: Sam Vaughan <email@hidden>
- Date: Mon, 2 Jun 2003 09:29:38 +1000
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.