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

Anna Zaks ganna at apple.com
Tue Jan 8 09:57:07 PST 2013


Scott, 

I do not see the new attribute and it's arguments documented anywhere. (In one of the pervious emails, Ted asked for the semantics of the attribute.) What happens when the allocation function fails to allocate? This is important since the user code often does not free the pointer on the failure path. Not handling this case would lead to false positives.

Also, have you tried to reuse the existing "ownership_returns" attribute? I think that would be cleaner. However, it would be good to see if it can be elegantly extended or not.

Other minor comments:
1) A lot of MallocMemRetPtrAux is a copy and paste from MallocMemAux. Is it possible to factor so that there is more code reuse?
2) 80 column rule.
3) We probably need more than one test.

Cheers,
Anna.


On Jan 6, 2013, at 10:00 PM, Scott Parlane <scott at scottnz.com> wrote:

> 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.
> 
> 
> <0001-Make-clang-static-analysis-support-allocation-into-a.patch>_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list