• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa application memory leak check
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Cocoa application memory leak check (From: XiaoGang Li <email@hidden>)
 >Re: Cocoa application memory leak check (From: WT <email@hidden>)
 >Re: Cocoa application memory leak check (From: Ken Ferry <email@hidden>)
 >Re: Cocoa application memory leak check (From: XiaoGang Li <email@hidden>)

  • Prev by Date: Re: Why is NSString->FSRef so hard?
  • Next by Date: Re: Why is NSString->FSRef so hard?
  • Previous by thread: Re: Cocoa application memory leak check
  • Next by thread: Problem when setting the background color using NSColorWell
  • Index(es):
    • Date
    • Thread