Re: Cocoa application memory leak check
Re: Cocoa application memory leak check
- Subject: Re: Cocoa application memory leak check
- From: Michael Ash <email@hidden>
- Date: Tue, 28 Apr 2009 00:56:31 -0400
On Mon, Apr 27, 2009 at 9:05 PM, XiaoGang Li <email@hidden> wrote:
> Thank you, WT and Ken Ferry.
> Yes, I also think Instruments is a static analyzer, so I am seeking a better
> tool for memory leak check, which support both static and dynamic checker.
> Hi, Ken, I have tried the static analyzers you mentioned. But it can not
> handle this kind of case, for example:
> //code start
> void *buffer1 = malloc(32);
> memset(buffer1,0,32);
> buffer1 = NULL;
>
> void *buffer2 = malloc(32);
> buffer2 = NULL;
>
> void *buffer3 = malloc(32);
> free(buffer3);
> buffer3 = NULL;
> //code end
>
> the results in this analysis run is werid. it only report the buffer2, the
> buffer1 is not checked out. Is it a bug for this tool? or do I also expect
> too much from this this checker.
Buffer 3 obviously is not wrong, so it doesn't show up. As for buffer
1, this is at least potentially correct as well. Without knowing what
memset() does, it's possible that it holds on to the pointer you pass
it and takes responsibility for freeing it. Unlike Cocoa, where
reference counting means that you can have consistent semantics no
matter where you pass pointers, straight malloc/free means that as
soon as your pointer escapes your code, the static analyzer has to
assume that something good is happening to it.
In this case, memset() is a standard C function whose semantics are
known, so in theory, if the static analyzer can prove that you're
calling that one (and not, say, a shadowed custom version or using a
#define to point it elsewhere) then it could flag this as a bug.
That's pretty sophisticated, though, and since it's only useful for a
limited subset of all available functions, it probably doesn't bother.
Mike
_______________________________________________
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