Re: Static Analyzer and Core Foundation
Re: Static Analyzer and Core Foundation
- Subject: Re: Static Analyzer and Core Foundation
- From: Chris Parker <email@hidden>
- Date: Fri, 18 Sep 2009 16:43:25 -0700
On 18 Sep 2009, at 4:33 PM, Steve Cronin wrote:
Alert - potential boneheaded-ness lies ahead - please be gentle.
I'll be the first to admit that I'm much happier in ObjC than C…
I thought I would try static analysis and see what turned up.
On the whole I must say I'm pleased but this one has me questioning
my basic understanding
if (![[NSFileManager defaultManager] fileExistsAtPath:thisPath]) {
…
41 } else {
42 MDItemRef mdi = MDItemCreate( nil, (CFStringRef)thisPath );
43 if ( mdi != nil ) {
44 CFDictionaryRef dictRef = MDItemCopyAttributes( mdi,
MDItemCopyAttributeNames(mdi));
…
CFRelease(dictRef);
} else {
… handle error
}
}
Static Analysis tells me I have a potential leak of object allocated
on line 44 -- that's all.
My questions are:
1) Why is there not a warning for the object allocated on line 42 -
mdi ?
Seems like it should be; you're not releasing it and it's going out of
scope.
2) Why is the CFRelease(dictRef) not sufficient?
In this case, it's probably complaining about the
MDItemCopyAttributeNames() call, which (because it has "Copy" in the
name) returns an object you'd have to release.
I.e., line 44 allocates two objects, the dictionary which you *are*
releasing and the attribute names array, which you're not.
.chris
--
Chris Parker
Apple Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden