[cfe-dev] RFC: static analysis, malloc annontation for return via pointer argument

Scott Parlane scott at scottnz.com
Sun Jan 6 22:00:02 PST 2013


Hi,

I have attached a new patch with the attribute name changed.

I think that extensions for size, family != malloc, binding return value
to pointer can be done separately.

I need to implement the family support one as part of the work I'm
currently doing. I intend to change it to name the free function to use,
instead of the allocator, I think this will be simpler.

Cheers,
Scott

On Mon, 2012-12-17 at 15:32 -0800, Ted Kremenek wrote:
> On Dec 17, 2012, at 1:55 PM, Scott Parlane <scott at scottnz.com> wrote:
> 
> > This patch allows for APIs were memory is allocated and placed in a
> > pointer given to them. (like asprintf, but without the realloc
> > feature)
> 
> 
> Thanks Scott.  I'm not such a fan of the name of the attribute.  Since
> this is returning an object by reference, how
> about ownership_returns_byref?  I'm sure others will have an opinion,
> but ownership_returns_pointer really doesn't tell the user what this
> attribute does.
> 
> 
> As for the implementation itself, it looks okay.  The annotation
> support eventually needs to be migrated from the
> alpha.unix.MallocWithAnnotations checker to the unix.Malloc checker
> (same file, logic controlled with a flag), but that's a separate
> issue.
> 
> 
> > 
> > Currently, when using a pointer to a stack variable as the input to
> > the
> > function, it declares the memory leak on the next source line after
> > the
> > stack variable is used. I think it should be declaring the leak on
> > the
> > last line of the current scope. Which is correct ?
> 
> The current behavior is correct.  The current scope could be very big,
> and may end long after the leak occurs.  We have found that reporting
> leaks as close as possible to where the leak occurred is a much better
> experience for users.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Make-clang-static-analysis-support-allocation-into-a.patch
Type: text/x-patch
Size: 11079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130107/f8e6788e/attachment.bin>


More information about the cfe-dev mailing list